mirror of
https://github.com/DependencyTrack/dependency-track.git
synced 2025-10-19 16:03:19 +00:00
Prevent duplicate tag names and relationships
Signed-off-by: nscuro <nscuro@protonmail.com>
This commit is contained in:
parent
f5c25f840d
commit
9c109dec99
26 changed files with 433 additions and 93 deletions
|
@ -458,7 +458,7 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
* @return the created Project
|
||||
*/
|
||||
@Override
|
||||
public Project createProject(final Project project, List<Tag> tags, boolean commitIndex) {
|
||||
public Project createProject(final Project project, Collection<Tag> tags, boolean commitIndex) {
|
||||
if (project.getParent() != null && !Boolean.TRUE.equals(project.getParent().isActive())){
|
||||
throw new IllegalArgumentException("An inactive Parent cannot be selected as parent");
|
||||
}
|
||||
|
@ -470,8 +470,19 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
persist(oldLatestProject);
|
||||
}
|
||||
|
||||
if (project.getCollectionLogic() == ProjectCollectionLogic.AGGREGATE_DIRECT_CHILDREN_WITH_TAG
|
||||
&& project.getCollectionTag() != null) {
|
||||
final Tag resolvedCollectionTag = resolveTags(List.of(project.getCollectionTag())).iterator().next();
|
||||
project.setCollectionTag(resolvedCollectionTag);
|
||||
} else {
|
||||
project.setCollectionTag(null);
|
||||
}
|
||||
|
||||
// Ensure that tags are not created implicitly but go through resolveTags instead.
|
||||
final Set<Tag> resolvedTags = resolveTags(tags);
|
||||
project.setTags(null);
|
||||
|
||||
final Project newProject = persist(project);
|
||||
final List<Tag> resolvedTags = resolveTags(tags);
|
||||
bind(project, resolvedTags);
|
||||
return newProject;
|
||||
});
|
||||
|
@ -569,16 +580,16 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
persist(oldLatestProject);
|
||||
}
|
||||
|
||||
final List<Tag> resolvedTags = resolveTags(transientProject.getTags());
|
||||
final Set<Tag> resolvedTags = resolveTags(transientProject.getTags());
|
||||
bind(project, resolvedTags);
|
||||
|
||||
// Set collection tag only if selected collectionLogic requires it. Clear it otherwise.
|
||||
if(transientProject.getCollectionLogic().equals(ProjectCollectionLogic.AGGREGATE_DIRECT_CHILDREN_WITH_TAG) &&
|
||||
transientProject.getCollectionTag() != null) {
|
||||
final List<Tag> resolvedCollectionTags = resolveTags(Collections.singletonList(
|
||||
final Set<Tag> resolvedCollectionTags = resolveTags(Collections.singletonList(
|
||||
transientProject.getCollectionTag()
|
||||
));
|
||||
project.setCollectionTag(resolvedCollectionTags.get(0));
|
||||
project.setCollectionTag(resolvedCollectionTags.iterator().next());
|
||||
} else {
|
||||
project.setCollectionTag(null);
|
||||
}
|
||||
|
@ -1377,7 +1388,7 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
boolean modified = false;
|
||||
|
||||
if (project.getTags() == null) {
|
||||
project.setTags(new ArrayList<>());
|
||||
project.setTags(new HashSet<>());
|
||||
}
|
||||
|
||||
if (!keepExisting) {
|
||||
|
@ -1397,8 +1408,8 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
project.getTags().add(tag);
|
||||
|
||||
if (tag.getProjects() == null) {
|
||||
tag.setProjects(new ArrayList<>(List.of(project)));
|
||||
} else if (!tag.getProjects().contains(project)) {
|
||||
tag.setProjects(new HashSet<>(Set.of(project)));
|
||||
} else {
|
||||
tag.getProjects().add(project);
|
||||
}
|
||||
|
||||
|
@ -1416,7 +1427,7 @@ final class ProjectQueryManager extends QueryManager implements IQueryManager {
|
|||
* @param tags a List of Tag objects
|
||||
*/
|
||||
@Override
|
||||
public void bind(final Project project, final List<Tag> tags) {
|
||||
public void bind(final Project project, final Collection<Tag> tags) {
|
||||
bind(project, tags, /* keepExisting */ false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue