-
Notifications
You must be signed in to change notification settings - Fork 327
feat: add copyProject method to ProjectService thrift definition #3915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
87ed99e
2c421ac
d2cb37e
9c23783
9ac8d4f
8b7ff0c
1034536
384ea4e
7528a14
d108e4e
4fbe622
e207b57
94e3519
96f8be9
446f71b
6f99045
cf330b7
fe7b661
337324b
05f2695
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ | |
| import org.eclipse.sw360.spdx.SpdxBOMImporterSink; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.beans.Visibility; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid import. Please remove. |
||
| import java.io.*; | ||
| import java.net.MalformedURLException; | ||
| import java.nio.charset.Charset; | ||
|
|
@@ -73,6 +74,9 @@ | |
| import java.util.function.Predicate; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
|
|
||
|
Comment on lines
+78
to
+79
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please remove irrelevant changes. |
||
|
|
||
| import static com.google.common.base.Strings.isNullOrEmpty; | ||
| import static org.eclipse.sw360.datahandler.common.CommonUtils.*; | ||
|
|
@@ -87,7 +91,8 @@ | |
| import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException; | ||
| import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission; | ||
| import org.eclipse.sw360.exporter.ProjectExporter; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please remove irrelevant changes. |
||
|
|
||
| /** | ||
| * Class for accessing the CouchDB database | ||
|
|
@@ -261,7 +266,7 @@ public AddDocumentRequestSummary createClearingRequest(ClearingRequest clearingR | |
| .setId(project.getClearingRequestId()).setMessage("Clearing request already present for project"); | ||
| } | ||
|
|
||
| if (!(ProjectClearingState.CLOSED.equals(project.getClearingState()) || Visibility.PRIVATE.equals(project.getVisbility()))) { | ||
| if (!(ProjectClearingState.CLOSED.equals(project.getClearingState()) || org.eclipse.sw360.datahandler.thrift.Visibility.PRIVATE.equals(project.getVisbility()))) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant change. Please revert. |
||
| clearingRequest.setProjectBU(project.getBusinessUnit()); | ||
| String crId = moderator.createClearingRequest(clearingRequest, user); | ||
| if (CommonUtils.isNotNullEmptyOrWhitespace(crId)) { | ||
|
|
@@ -478,7 +483,7 @@ public RequestStatus updateProject(Project project, User user, boolean forceUpda | |
| Collections.emptySet())))) { | ||
| return RequestStatus.INVALID_INPUT; | ||
| } else if (isWriteActionAllowedOnProject(actual, user) || forceUpdate) { | ||
| copyImmutableFields(project,actual); | ||
|
|
||
| setRequestedDateAndTrimComment(project, actual, user); | ||
| setRequestedDateAndTrimCommentForPackages(project, actual, user); | ||
| project.setAttachments( getAllAttachmentsToKeep(toSource(actual), actual.getAttachments(), project.getAttachments()) ); | ||
|
|
@@ -568,6 +573,18 @@ private List<AttachmentUsage> parseAttachmentUsages(List<String> projectPaths, S | |
| } | ||
| String releaseId = usage.getOwner().getReleaseId(); | ||
| String attachmentContentId = usage.getAttachmentContentId(); | ||
| AttachmentUsage newUsage = new AttachmentUsage(Source.releaseId(releaseId), attachmentContentId, org.eclipse.sw360.datahandler.thrift.Source.projectId(projectId)); | ||
| final UsageData usageData; | ||
| LicenseInfoUsage licenseInfoUsage = new LicenseInfoUsage(Collections.emptySet()); | ||
| licenseInfoUsage.setProjectPath(projectPath); | ||
| usageData = UsageData.licenseInfo(licenseInfoUsage); | ||
| newUsage.setUsageData(usageData); | ||
| result.add(newUsage); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+583
to
+585
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ummm... What? |
||
| String releaseId = usage.getOwner().getReleaseId(); | ||
| String attachmentContentId = usage.getAttachmentContentId(); | ||
| AttachmentUsage newUsage = new AttachmentUsage( | ||
| Source.releaseId(releaseId), attachmentContentId, Source.projectId(projectId)); | ||
| LicenseInfoUsage licenseInfoUsage = new LicenseInfoUsage(Collections.emptySet()); | ||
|
|
@@ -908,7 +925,7 @@ private ObligationList deleteObligationsOfUnlinkedReleases(Project updated) { | |
| } | ||
|
|
||
| private void updateProjectDependentLinkedFields(Project updated, Project actual) throws SW360Exception { | ||
| Source usedBy = Source.projectId(updated.getId()); | ||
| org.eclipse.sw360.datahandler.thrift.Source usedBy =org.eclipse.sw360.datahandler.thrift.Source.projectId(updated.getId()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant change. Please revert. |
||
| Set<String> updatedLinkedReleaseIds = nullToEmptyMap(updated.getReleaseIdToUsage()).keySet(); | ||
| Set<String> actualLinkedReleaseIds = nullToEmptyMap(actual.getReleaseIdToUsage()).keySet(); | ||
| deleteAttachmentUsagesOfUnlinkedReleases(usedBy, updatedLinkedReleaseIds, actualLinkedReleaseIds); | ||
|
|
@@ -1028,12 +1045,67 @@ public RequestStatus updateProjectFromAdditionsAndDeletions(Project projectAddit | |
| } | ||
|
|
||
| } | ||
| /////////////////////////////// | ||
| // COPY PROJECT // | ||
| ///////////////////////////// | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please fix indentation. |
||
|
|
||
| private void copyImmutableFields(Project destination, Project source) { | ||
| ThriftUtils.copyField(source, destination, Project._Fields.CREATED_ON); | ||
| ThriftUtils.copyField(source, destination, Project._Fields.CREATED_BY); | ||
| public AddDocumentRequestSummary copyProject(String projectId, Set<String> fieldsToCopy, Project overrideFields, User user) throws TException { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please fix indentation. |
||
| Project sourceProject = getProjectById(projectId, user); | ||
| if (sourceProject == null) { | ||
| return new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.INVALID_INPUT); | ||
| } | ||
|
|
||
| Project newProject = new Project(); | ||
|
|
||
| // Default: copy ALL non-internal fields if empty (per GMishx feedback) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to mention names :-) |
||
| if (fieldsToCopy.isEmpty()) { | ||
| fieldsToCopy = Stream.of(Project._Fields.values()) | ||
| .filter(f -> !"ID".equals(f.name()) && | ||
| !"CREATED_ON".equals(f.name()) && | ||
| !"CREATED_BY".equals(f.name()) && | ||
| !"REVISION".equals(f.name()) && | ||
| !"CLEARING_STATE".equals(f.name()) && | ||
| !"CLEARING_REQUEST_ID".equals(f.name())) | ||
| .map(Enum::name) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| // Always copy the name (required field) | ||
| newProject.setName(sourceProject.getName() + " (Copy)"); | ||
|
|
||
| // Copy only the fields requested by the user | ||
| for (String fieldName : fieldsToCopy) { | ||
| try { | ||
| Project._Fields field = Project._Fields.findByName(fieldName); | ||
| if (field != null && sourceProject.isSet(field)) { | ||
| ThriftUtils.copyField(sourceProject, newProject, field); | ||
| } | ||
| } catch (Exception e) { | ||
| log.warn("Could not copy field: " + fieldName, e); | ||
| } | ||
| } | ||
|
|
||
| // Reset fields that must not be carried over | ||
| newProject.unsetId(); | ||
| newProject.unsetRevision(); | ||
| newProject.unsetCreatedBy(); | ||
| newProject.unsetCreatedOn(); | ||
| newProject.unsetClearingRequestId(); | ||
| newProject.unsetClearingState(); | ||
|
|
||
| // Apply user overrides (name, version, etc.) | ||
| if (overrideFields != null) { | ||
| if (overrideFields.isSetName()) { | ||
| newProject.setName(overrideFields.getName()); | ||
| } | ||
| if (overrideFields.isSetVersion()) { | ||
| newProject.setVersion(overrideFields.getVersion()); | ||
| } | ||
| } | ||
|
|
||
| return addProject(newProject, user); | ||
| } | ||
|
|
||
| /////////////////////////////// | ||
| // DELETE INDIVIDUAL OBJECTS // | ||
| /////////////////////////////// | ||
|
|
@@ -1215,7 +1287,7 @@ public Project getProjectForEdit(String id, User user) throws SW360Exception { | |
| List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id); | ||
|
|
||
| Project project = getProjectById(id,user); | ||
| Visibility actualVisbility = project.getVisbility(); | ||
| org.eclipse.sw360.datahandler.thrift.Visibility actualVisbility = project.getVisbility(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant change. Please revert. |
||
| DocumentState documentState; | ||
| if (moderationRequestsForDocumentId.isEmpty()) { | ||
| documentState = CommonUtils.getOriginalDocumentState(); | ||
|
|
@@ -1455,7 +1527,7 @@ public List<Project> fillClearingStateSummaryIncludingSubprojects(List<Project> | |
|
|
||
| projects.stream().forEach(project -> { | ||
| // build project tree, get all linked release ids and fetch the releases | ||
| // current decision is to not check any permissions for subproject visibility | ||
| // current decision is to not check any permissions for subprojectorg.eclipse.sw360.datahandler.thrift.Visibility | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What? |
||
| Set<String> releaseIdsOfProjectTree = getReleaseIdsOfProjectTree(project, Sets.newHashSet(), | ||
| allProjectsIdMap, user, null); | ||
| List<Release> releasesForClearingStateSummary = componentDatabaseHandler | ||
|
|
@@ -1921,7 +1993,7 @@ private String extractProjectNamesForEmail(Collection<Project> projects) { | |
| /** | ||
| * CAUTION! | ||
| * You should most probably use {@link #getAccessibleProjects(User)} instead of this method. | ||
| * This method reads all the projects without checking for visibility constraints. It is intended to provide | ||
| * This method reads all the projects without checking fororg.eclipse.sw360.datahandler.thrift.Visibility constraints. It is intended to provide | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😕 |
||
| * all projects for export from a scheduled service, where a valid sw360 user is not available. | ||
| * This is a less than optimal situation, but that's the way it is at the moment. | ||
| * @return list of all projects in the database | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| import org.mockito.Mockito; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import java.beans.Visibility; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import. Please remove. |
||
| import java.util.*; | ||
|
|
||
| import static org.eclipse.sw360.datahandler.TestUtils.assertTestString; | ||
|
|
@@ -40,6 +41,10 @@ | |
| import static org.mockito.Mockito.lenient; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import org.eclipse.sw360.datahandler.thrift.projects.Project; | ||
| import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class ProjectDatabaseHandlerTest { | ||
|
|
||
|
|
@@ -444,4 +449,18 @@ private ProjectWithReleaseRelationTuple createTuple(Project p) { | |
| private ProjectReleaseRelationship newDefaultProjectReleaseRelationship() { | ||
| return new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.MAINLINE); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Test | ||
| public void testCopyProjectWithEmptyFields() throws Exception { | ||
|
Comment on lines
+452
to
+456
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please fix indentation. |
||
| Set<String> emptyFields = new HashSet<>(); | ||
| Project dummyOverride = new Project(); | ||
| dummyOverride.setId("targetId"); | ||
|
|
||
| AddDocumentRequestSummary result = handler.copyProject( | ||
| "P1", emptyFields, dummyOverride, user1); | ||
|
|
||
| assertNotNull("Result should not be null", result); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,6 +354,10 @@ public AddDocumentRequestSummary addProject(Project project, User user) throws T | |
| assertUser(user); | ||
| validateNoEmptyKeys(project); | ||
| return handler.addProject(project, user); | ||
| @Override | ||
| public AddDocumentRequestSummary copyProject(String projectId, Set<String> fieldsToCopy, Project overrideFields, User user) throws SW360Exception { return projectDatabaseHandler.copyProject(projectId, fieldsToCopy, overrideFields, user); | ||
|
Comment on lines
+357
to
+358
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad code styling. Please fix indentation.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this is not the style SW360 follows. There should be newline after the Use the linting suggested! |
||
| } | ||
|
|
||
| } | ||
|
|
||
| /////////////////////////////// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant change. Please revert. |
||
| <!-- | ||
| ~ Copyright Siemens AG, 2013-2015, 2019. Part of the SW360 Portal Project. | ||
| ~ | ||
|
|
@@ -8,6 +7,9 @@ | |
| ~ | ||
| ~ SPDX-License-Identifier: EPL-2.0 | ||
| --> | ||
|
|
||
|
|
||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
@@ -34,7 +36,7 @@ | |
| <artifactId>maven-thrift-plugin</artifactId> | ||
| <version>0.1.11</version> | ||
| <configuration> | ||
| <thriftExecutable>thrift</thriftExecutable> | ||
| <thriftExecutable>thrift</thriftExecutable> | ||
| <generator>java:generated_annotations=suppress</generator> | ||
| <checkStaleness>true</checkStaleness> | ||
| </configuration> | ||
|
|
@@ -122,12 +124,10 @@ | |
| <configuration> | ||
| <artifactItems combine.children="append"> | ||
| <artifactItem> | ||
| <groupId> | ||
| org.eclipse.sw360</groupId> | ||
| <groupId>org.eclipse.sw360</groupId> | ||
| <artifactId>build-configuration</artifactId> | ||
| <version>${project.version}</version> | ||
| <type> | ||
| jar</type> | ||
| <type>jar</type> | ||
| <outputDirectory>${project.build.outputDirectory}</outputDirectory> | ||
| </artifactItem> | ||
| </artifactItems> | ||
|
|
@@ -142,12 +142,10 @@ | |
| <configuration> | ||
| <artifactItems combine.children="append"> | ||
| <artifactItem> | ||
| <groupId> | ||
| org.eclipse.sw360</groupId> | ||
| <groupId>org.eclipse.sw360</groupId> | ||
| <artifactId>build-configuration</artifactId> | ||
| <version>${project.version}</version> | ||
| <type> | ||
| test-jar</type> | ||
| <type>test-jar</type> | ||
| <outputDirectory>${project.build.testOutputDirectory}</outputDirectory> | ||
| </artifactItem> | ||
| </artifactItems> | ||
|
|
@@ -261,4 +259,4 @@ | |
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.eclipse.sw360.rest.resourceserver.project; | ||
|
|
||
| import org.eclipse.sw360.datahandler.thrift.projects.Project; | ||
| import java.util.Set; | ||
|
|
||
| public class CopyProjectRequest { | ||
| private Set<String> fieldsToCopy; | ||
| private Project overrideFields; | ||
|
|
||
| public Set<String> getFieldsToCopy() { return fieldsToCopy; } | ||
| public void setFieldsToCopy(Set<String> fieldsToCopy) { this.fieldsToCopy = fieldsToCopy; } | ||
| public Project getOverrideFields() { return overrideFields; } | ||
| public void setOverrideFields(Project overrideFields) { this.overrideFields = overrideFields; } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committing a binary file is a big no no!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still here.