From 709a5ec90d76a84cde07065ade29cc7461a48198 Mon Sep 17 00:00:00 2001 From: Abdul Kapti Date: Tue, 24 May 2022 18:52:09 +0530 Subject: [PATCH] feat(UI): ModifiedOn & MOdifiedBy fields for Project/COmponent/Release Signed-off-by: Abdul Kapti --- .../db/AttachmentAwareDatabaseHandler.java | 19 ++++++++++ .../db/ComponentDatabaseHandler.java | 35 +++++++++++++------ .../db/ProjectDatabaseHandler.java | 2 ++ .../sw360/components/ComponentHandler.java | 6 ++-- .../sw360/vendors/VendorDatabaseHandler.java | 2 +- .../includes/components/editBasicInfo.jspf | 18 ++++++++-- .../includes/components/summary.jspf | 8 +++++ .../releases/editReleaseInformation.jspf | 19 ++++++++++ .../includes/releases/summaryRelease.jspf | 8 +++++ .../projects/includes/projects/basicInfo.jspf | 18 ++++++++++ .../projects/includes/projects/summary.jspf | 8 +++++ .../resources/content/Language.properties | 1 + .../resources/content/Language_ja.properties | 1 + .../resources/content/Language_vi.properties | 1 + .../src/main/thrift/components.thrift | 6 +++- .../src/main/thrift/projects.thrift | 2 ++ .../core/JacksonCustomizations.java | 16 +++++++-- 17 files changed, 151 insertions(+), 19 deletions(-) diff --git a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentAwareDatabaseHandler.java b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentAwareDatabaseHandler.java index 42d50ad008..076cd224c3 100644 --- a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentAwareDatabaseHandler.java +++ b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/AttachmentAwareDatabaseHandler.java @@ -19,6 +19,9 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import org.apache.thrift.TBase; +import org.apache.thrift.TFieldIdEnum; +import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.thrift.SW360Exception; import org.eclipse.sw360.datahandler.thrift.Source; import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; @@ -84,4 +87,20 @@ protected void deleteAttachmentUsagesOfUnlinkedReleases(Source usedBy, Set owners = deletedLinkedReleaseIds.stream().map(Source::releaseId).collect(Collectors.toSet()); attachmentDatabaseHandler.deleteUsagesBy(usedBy, owners); } + + protected > void updateModifiedFields(T type, String userEmail) { + if (type instanceof Release) { + Release release = (Release) type; + release.setModifiedBy(userEmail); + release.setModifiedOn(SW360Utils.getCreatedOn()); + } else if (type instanceof Component) { + Component component = (Component) type; + component.setModifiedBy(userEmail); + component.setModifiedOn(SW360Utils.getCreatedOn()); + } else if (type instanceof Project) { + Project project = (Project) type; + project.setModifiedBy(userEmail); + project.setModifiedOn(SW360Utils.getCreatedOn()); + } + } } diff --git a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java index f12137c5b8..eee34caba0 100644 --- a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java +++ b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java @@ -499,6 +499,7 @@ public AddDocumentRequestSummary addRelease(Release release, User user) throws S } Component oldComponent = component.deepCopy(); updateReleaseDependentFieldsForComponent(component, release); + updateModifiedFields(component, user.getEmail()); componentRepository.update(component); sendMailNotificationsForNewRelease(release, user.getEmail()); @@ -673,6 +674,7 @@ private void updateComponentDependentFieldsForRelease(Component component, List< changes.add(nameFields); changeLog.setChanges(changes); release.setName(name); + updateModifiedFields(release, userEdited); releaseRepository.update(release); referenceDocLogList.add(changeLog); } @@ -696,6 +698,7 @@ private boolean duplicateAttachmentExist(Component component) { private void updateComponentInternal(Component updated, Component current, User user) { + updateModifiedFields(updated, user.getEmail()); // Update the database with the component componentRepository.update(updated); @@ -891,6 +894,7 @@ private void transferReleases(Set releaseIds, Component mergeTarget, Com private void updateReleasesAfterMerge(Set targetComponentReleaseIds, Set srcComponentReleaseIds, Component mergeSelection, Component mergeTarget, User sessionUser) throws SW360Exception { + final String userEmail = sessionUser.getEmail(); // Change release name if appropriate List targetComponentReleases = getReleasesForClearingStateSummary(targetComponentReleaseIds); List srcComponentReleases = getReleasesForClearingStateSummary(srcComponentReleaseIds); @@ -909,7 +913,8 @@ private void updateReleasesAfterMerge(Set targetComponentReleaseIds, Set } r.setComponentId(mergeTarget.getId()); r.setName(mergeSelection.getName()); - dbHandlerUtil.addChangeLogs(r, releaseBefore, sessionUser.getEmail(), Operation.UPDATE, + updateModifiedFields(r, userEmail); + dbHandlerUtil.addChangeLogs(r, releaseBefore, userEmail, Operation.UPDATE, attachmentConnector, Lists.newArrayList(), mergeTarget.getId(), Operation.MERGE_COMPONENT); return r; }).collect(Collectors.toList()); @@ -936,7 +941,7 @@ private void updateComponentCompletely(Component component, User user) throws SW private void updateComponentCompletelyWithoutDeletingAttachment(Component component, User user) throws SW360Exception { // Prepare component for database prepareComponent(component); - + updateModifiedFields(component, user.getEmail()); componentRepository.update(component); sendMailNotificationsForComponentUpdate(component, user.getEmail()); @@ -1001,10 +1006,11 @@ public RequestStatus updateRelease(Release release, User user, Iterable projects = projectClient.searchByReleaseId(mergeSourceId, sessionUser); for(Project project : projects) { // retrieve full document, other method only retrieves summary @@ -1489,9 +1498,10 @@ private void updateReleaseReferencesInProjects(String mergeTargetId, String merg if(!project.getReleaseIdToUsage().containsKey(mergeTargetId)) { project.putToReleaseIdToUsage(mergeTargetId, relationship); } + updateModifiedFields(project, userEmail); projectClient.updateProject(project, sessionUser); - dbHandlerUtil.addChangeLogs(project, projectBefore, sessionUser.getEmail(), Operation.UPDATE, + dbHandlerUtil.addChangeLogs(project, projectBefore, userEmail, Operation.UPDATE, attachmentConnector, Lists.newArrayList(), mergeTargetId, Operation.MERGE_RELEASE); } } @@ -1597,7 +1607,7 @@ public RequestStatus deleteComponent(String id, User user) throws SW360Exception for (Release release : releaseRepository.get(nullToEmptySet(component.releaseIds))) { - component = removeReleaseAndCleanUp(release); + component = removeReleaseAndCleanUp(release, user); } // Remove the component with attachments @@ -1645,11 +1655,11 @@ public boolean checkIfInUse(String releaseId) { return (usingProjects.size() > 0); } - private Component removeReleaseAndCleanUp(Release release) throws SW360Exception { + private Component removeReleaseAndCleanUp(Release release, User user) throws SW360Exception { attachmentConnector.deleteAttachments(release.getAttachments()); attachmentDatabaseHandler.deleteUsagesBy(Source.releaseId(release.getId())); - Component component = updateReleaseDependentFieldsForComponentId(release.getComponentId()); + Component component = updateReleaseDependentFieldsForComponentId(release.getComponentId(), user); //TODO notify using projects!?? Or stop if there are any @@ -1669,7 +1679,7 @@ public RequestStatus deleteRelease(String id, User user) throws SW360Exception { Component componentBefore = componentRepository.get(release.getComponentId()); // Remove release id from component removeReleaseId(id, release.componentId); - Component componentAfter=removeReleaseAndCleanUp(release); + Component componentAfter=removeReleaseAndCleanUp(release, user); dbHandlerUtil.addChangeLogs(null, release, user.getEmail(), Operation.DELETE, attachmentConnector, Lists.newArrayList(), null, null); dbHandlerUtil.addChangeLogs(componentAfter, componentBefore, user.getEmail(), Operation.UPDATE, @@ -2212,8 +2222,9 @@ public RequestStatus splitComponent(Component srcComponent, Component targetComp recomputeReleaseDependentFields(srcComponentFromDB, null); targetComponentFromDB.unsetReleases(); srcComponentFromDB.unsetReleases(); + updateModifiedFields(targetComponentFromDB, user.getEmail()); componentRepository.update(targetComponentFromDB); - + updateModifiedFields(srcComponentFromDB, user.getEmail()); componentRepository.update(srcComponentFromDB); updateReleaseAfterComponentSplit(srcComponentFromDBOriginal, targetComponentFromDBOriginal, @@ -2466,6 +2477,7 @@ private void updateReleaseAfterComponentSplit(Component srcComponentFromDB, Comp List srcComponentReleasesMoved = getReleasesForClearingStateSummary(srcComponentReleaseIdsMovedFromSrc); Set targetComponentReleaseVersions = targetComponentReleases.stream().map(Release::getVersion) .collect(Collectors.toSet()); + final String userEmail = user.getEmail(); List releasesToUpdate = srcComponentReleasesMoved.stream().map(r -> { Release releaseBefore = r.deepCopy(); @@ -2476,7 +2488,8 @@ private void updateReleaseAfterComponentSplit(Component srcComponentFromDB, Comp } r.setComponentId(targetComponentFromDB.getId()); r.setName(targetComponentFromDB.getName()); - dbHandlerUtil.addChangeLogs(r, releaseBefore, user.getEmail(), Operation.UPDATE, attachmentConnector, + updateModifiedFields(r, userEmail); + dbHandlerUtil.addChangeLogs(r, releaseBefore, userEmail, Operation.UPDATE, attachmentConnector, Lists.newArrayList(), srcComponentFromDB.getId(), Operation.SPLIT_COMPONENT); return r; }).collect(Collectors.toList()); diff --git a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java index 3a108b0d36..1a851f169e 100644 --- a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java +++ b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java @@ -411,6 +411,7 @@ public RequestStatus updateProject(Project project, User user) throws SW360Excep setReleaseRelations(project, user, actual); updateProjectDependentLinkedFields(project, actual); project.unsetVendor(); + updateModifiedFields(project, user.getEmail()); repository.update(project); List referenceDocLogList=new LinkedList<>(); @@ -570,6 +571,7 @@ public RequestStatus addLinkedObligations(ObligationList obligation, User user) obligationRepository.add(obligation); Project project = getProjectById(obligation.getProjectId(), user); project.setLinkedObligationId(obligation.getId()); + updateModifiedFields(project, user.getEmail()); repository.update(project); project.unsetLinkedObligationId(); dbHandlerUtil.addChangeLogs(obligation, null, user.getEmail(), Operation.CREATE, attachmentConnector, diff --git a/backend/src/src-components/src/main/java/org/eclipse/sw360/components/ComponentHandler.java b/backend/src/src-components/src/main/java/org/eclipse/sw360/components/ComponentHandler.java index 684d1e29ca..b10e0b0d1c 100644 --- a/backend/src/src-components/src/main/java/org/eclipse/sw360/components/ComponentHandler.java +++ b/backend/src/src-components/src/main/java/org/eclipse/sw360/components/ComponentHandler.java @@ -485,8 +485,10 @@ public boolean componentIsUsed(String componentId) throws TException { } @Override - public Component recomputeReleaseDependentFields(String componentId) throws TException { - return handler.updateReleaseDependentFieldsForComponentId(componentId); + public Component recomputeReleaseDependentFields(String componentId, User user) throws TException { + assertUser(user); + assertId(componentId); + return handler.updateReleaseDependentFieldsForComponentId(componentId, user); } ////////////////////////////////// diff --git a/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorDatabaseHandler.java b/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorDatabaseHandler.java index 1148977dc7..66bed9c123 100644 --- a/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorDatabaseHandler.java +++ b/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorDatabaseHandler.java @@ -182,7 +182,7 @@ private RequestSummary updateReleases(Vendor mergeTarget, Vendor mergeSource, Us // update computed fields of affected components for(String componentId : componentIds) { - componentsClient.recomputeReleaseDependentFields(componentId); + componentsClient.recomputeReleaseDependentFields(componentId, user); } return result; diff --git a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/editBasicInfo.jspf b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/editBasicInfo.jspf index f724f30759..e7b3bd020f 100644 --- a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/editBasicInfo.jspf +++ b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/editBasicInfo.jspf @@ -130,13 +130,27 @@ - +
-
+ +
+ + " + value="" readonly class="form-control"/> +
+ + +
+ +
+ diff --git a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/summary.jspf b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/summary.jspf index 28ebe159f1..ed46e3af1a 100644 --- a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/summary.jspf +++ b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/components/summary.jspf @@ -46,6 +46,14 @@ : + + : + + + + : + + : diff --git a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/releases/editReleaseInformation.jspf b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/releases/editReleaseInformation.jspf index ea46d9e09c..bad5b65dd3 100644 --- a/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/releases/editReleaseInformation.jspf +++ b/frontend/sw360-portlet/src/main/resources/META-INF/resources/html/components/includes/releases/editReleaseInformation.jspf @@ -188,6 +188,25 @@ description="moderators" multiUsers="true" readonly="false"/> + + + +
+ + " + value="" readonly class="form-control"/> +
+ + +
+ +
+ + + +