Skip to content

Commit

Permalink
Change field and columns from "templates" to "templateIds"
Browse files Browse the repository at this point in the history
  • Loading branch information
de-jcup committed Dec 3, 2024
1 parent 6586448 commit b48c9e8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Project {
public static final String COLUMN_METADATA = "METADATA_KEY";

public static final String COLUMN_PROJECT_ACCESS_LEVEL = "PROJECT_ACCESS_LEVEL";
public static final String COLUMN_TEMPLATES = "PROJECT_TEMPLATES";
public static final String COLUMN_TEMPLATE_ID = "PROJECT_TEMPLATE_ID";

public static final String ASSOCIATE_PROJECT_TO_USER_COLUMN_PROJECT_ID = "PROJECTS_PROJECT_ID";
public static final String ASSOCIATE_PROJECT_TO_URI_COLUMN_PROJECT_ID = "PROJECT_PROJECT_ID";
Expand Down Expand Up @@ -91,10 +91,10 @@ public class Project {
@OneToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.EAGER, mappedBy = ProjectMetaDataEntity.PROPERTY_PROJECT_ID)
Set<ProjectMetaDataEntity> metaData = new HashSet<>();

@Column(name = COLUMN_TEMPLATES, nullable = false)
@Column(name = COLUMN_TEMPLATE_ID, nullable = false)
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
@CollectionTable(name = TABLE_NAME_PROJECT_TEMPLATES)
Set<String> templates = new HashSet<>();
Set<String> templateIds = new HashSet<>();

@Version
@Column(name = "VERSION")
Expand Down Expand Up @@ -135,8 +135,8 @@ public ProjectAccessLevel getAccessLevel() {
return accessLevel;
}

public Set<String> getTemplates() {
return templates;
public Set<String> getTemplateIds() {
return templateIds;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ProjectDetailInformation {

private List<String> users = new ArrayList<>();
private List<String> whitelist = new ArrayList<>();
private List<String> templates = new ArrayList<>();
private List<String> templateIds = new ArrayList<>();
private Map<String, String> metaData = new HashMap<>();
private String owner;
private String description;
Expand All @@ -44,7 +44,7 @@ public ProjectDetailInformation(Project project) {

project.getMetaData().forEach(entry -> this.metaData.put(entry.key, entry.value));

project.getTemplates().forEach(templateid -> this.templates.add(templateid));
project.getTemplateIds().forEach(templateid -> this.templateIds.add(templateid));

this.owner = project.getOwner().getName();

Expand Down Expand Up @@ -81,7 +81,7 @@ public String getAccessLevel() {
return accessLevel;
}

public List<String> getTemplates() {
return templates;
public List<String> getTemplateIds() {
return templateIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public void assignTemplateToProject(String templateId, String projectId) {
assertion.assertIsValidProjectId(projectId);

Project project = projectRepository.findOrFailProject(projectId);
Set<String> templates = project.getTemplates();
LOG.debug("Start assigning template '{}' to project '{}'. Formerly assgined templates : {}", templateId, projectId, templates);
Set<String> templateIds = project.getTemplateIds();
LOG.debug("Start assigning template '{}' to project '{}'. Formerly assgined templates : {}", templateId, projectId, templateIds);

SecHubProjectTemplates result = sendAssignRequestAndFetchResult(templateId, projectId);
List<String> newTemplates = result.getTemplateIds();
templates.clear();
templates.addAll(newTemplates);
List<String> newTemplateIds = result.getTemplateIds();
templateIds.clear();
templateIds.addAll(newTemplateIds);

projectTansactionService.saveInOwnTransaction(project);
LOG.info("Assigned template '{}' to project '{}'", templateId, projectId);

LOG.debug("Project '{}' has now following templates: {}", templateId, projectId, templates);
LOG.debug("Project '{}' has now following templates: {}", projectId, templateIds);

}

Expand All @@ -83,18 +83,18 @@ public void unassignTemplateFromProject(String templateId, String projectId) {
assertion.assertIsValidProjectId(projectId);

Project project = projectRepository.findOrFailProject(projectId);
Set<String> templates = project.getTemplates();
LOG.debug("Start unassigning template '{}' from project '{}'. Formerly assgined templates : {}", templateId, projectId, templates);
Set<String> templateIds = project.getTemplateIds();
LOG.debug("Start unassigning template '{}' from project '{}'. Formerly assgined templates : {}", templateId, projectId, templateIds);

SecHubProjectTemplates result = sendUnassignRequestAndFetchResult(templateId, projectId);
List<String> newTemplates = result.getTemplateIds();
templates.clear();
templates.addAll(newTemplates);
List<String> newTemplateIds = result.getTemplateIds();
templateIds.clear();
templateIds.addAll(newTemplateIds);

projectTansactionService.saveInOwnTransaction(project);
LOG.info("Unassigned template '{}' from project '{}'", templateId, projectId);

LOG.debug("Project '{}' has now following templates: {}", templateId, projectId, templates);
LOG.debug("Project '{}' has now following templates: {}", projectId, templateIds);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void constructor_stores_data_from_project_into_fields() {
when(project.getOwner()).thenReturn(owner);
when(project.getMetaData()).thenReturn(Set.of(metaDataEntity));
when(project.getUsers()).thenReturn(Set.of(user1, user2));
when(project.getTemplates()).thenReturn(Set.of("template1", "template2"));
when(project.getTemplateIds()).thenReturn(Set.of("template1", "template2"));

/* execute */
ProjectDetailInformation toTest = new ProjectDetailInformation(project);
Expand All @@ -49,7 +49,7 @@ void constructor_stores_data_from_project_into_fields() {
assertThat(toTest.getOwner()).isEqualTo("owner1");
assertThat(toTest.getUsers()).contains("user1", "user2");
assertThat(toTest.getWhiteList()).contains("https://example.com");
assertThat(toTest.getTemplates()).contains("template1", "template2");
assertThat(toTest.getTemplateIds()).contains("template1", "template2");
assertThat(toTest.getMetaData()).containsEntry("key1", "value1");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void assertTemplateCanBeDeletedAndAssignmentIsPurged() {
as(SUPER_ADMIN).deleteTemplate(templateId);

/* test 5.1 check delete unassigns template */
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplates()).contains(templateId));
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplateIds()).contains(templateId));

/* test 5.2 check template no longer exists */
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchTemplateDefinitionOrNull(templateId)).isNull());
Expand All @@ -147,7 +147,7 @@ private void assertTemplateCanBeUnassignedFromProject() {
as(SUPER_ADMIN).unassignTemplateFromProject(templateId, Scenario1.PROJECT_1);

/* test 4 - check assignment */
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplates()).isEmpty());
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplateIds()).isEmpty());
executeResilient(() -> assertThat(fetchScanProjectConfigurations(Scenario1.PROJECT_1)).isEmpty());
}

Expand All @@ -157,7 +157,7 @@ private void assertTemplateCanBeAssignedToProject() {
as(SUPER_ADMIN).assignTemplateToProject(templateId, Scenario1.PROJECT_1);

/* test 3.1 - check assignment by project details in domain administration */
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplates()).contains(templateId));
executeResilient(() -> assertThat(as(SUPER_ADMIN).fetchProjectDetailInformation(Scenario1.PROJECT_1).getTemplateIds()).contains(templateId));

/* test 3.2 - check project scan configuration in domain scan */
executeResilient(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ CREATE INDEX IF NOT EXISTS i02_scan_template_id
CREATE TABLE adm_project_templates
(
project_project_id varchar(60) not null, -- we accept 60 (3x20), see ProjectIdValidation
project_templates varchar(40) not null,
PRIMARY KEY (project_project_id, project_templates)
project_template_id varchar(40) not null,
PRIMARY KEY (project_project_id, project_template_id)
);

ALTER TABLE adm_project_templates ADD CONSTRAINT c09_adm_project_template_project_id FOREIGN KEY (project_project_id) REFERENCES adm_project (project_id);
Expand Down

0 comments on commit b48c9e8

Please sign in to comment.