Skip to content

Commit

Permalink
Merge branch 'master' into releases/feature-spdx_information_management
Browse files Browse the repository at this point in the history
  • Loading branch information
tuannn2 committed Jun 23, 2022
2 parents 229c90d + 4678016 commit 1e45b5b
Show file tree
Hide file tree
Showing 23 changed files with 303 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,4 +87,20 @@ protected void deleteAttachmentUsagesOfUnlinkedReleases(Source usedBy, Set<Strin
Set<Source> owners = deletedLinkedReleaseIds.stream().map(Source::releaseId).collect(Collectors.toSet());
attachmentDatabaseHandler.deleteUsagesBy(usedBy, owners);
}

protected <T extends TBase<T, ? extends TFieldIdEnum>> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,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());
Expand Down Expand Up @@ -705,6 +706,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);
}
Expand All @@ -728,6 +730,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);

Expand Down Expand Up @@ -923,6 +926,7 @@ private void transferReleases(Set<String> releaseIds, Component mergeTarget, Com

private void updateReleasesAfterMerge(Set<String> targetComponentReleaseIds, Set<String> srcComponentReleaseIds,
Component mergeSelection, Component mergeTarget, User sessionUser) throws SW360Exception {
final String userEmail = sessionUser.getEmail();
// Change release name if appropriate
List<Release> targetComponentReleases = getReleasesForClearingStateSummary(targetComponentReleaseIds);
List<Release> srcComponentReleases = getReleasesForClearingStateSummary(srcComponentReleaseIds);
Expand All @@ -941,7 +945,8 @@ private void updateReleasesAfterMerge(Set<String> 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());
Expand All @@ -968,7 +973,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());
Expand Down Expand Up @@ -1033,10 +1038,11 @@ public RequestStatus updateRelease(Release release, User user, Iterable<Release.
}

checkSuperAttachmentExists(release);
updateModifiedFields(release, user.getEmail());
releaseRepository.update(release);
String componentId=release.getComponentId();
Component oldComponent = componentRepository.get(componentId);
Component updatedComponent = updateReleaseDependentFieldsForComponentId(componentId);
Component updatedComponent = updateReleaseDependentFieldsForComponentId(componentId, user);
// clean up attachments in database
attachmentConnector.deleteAttachmentDifference(nullToEmptySet(actual.getAttachments()),
nullToEmptySet(release.getAttachments()));
Expand Down Expand Up @@ -1266,9 +1272,10 @@ public RequestStatus updateReleaseFromAdditionsAndDeletions(Release releaseAddit

}

public Component updateReleaseDependentFieldsForComponentId(String componentId) {
public Component updateReleaseDependentFieldsForComponentId(String componentId, User user) {
Component component = componentRepository.get(componentId);
recomputeReleaseDependentFields(component, null);
updateModifiedFields(component, user.getEmail());
componentRepository.update(component);

return component;
Expand Down Expand Up @@ -1497,6 +1504,7 @@ private void updateReleaseCompletely(Release release, User user, boolean updateC
if(updateClearingState) {
autosetReleaseClearingState(release, actual);
}
updateModifiedFields(release, user.getEmail());
releaseRepository.update(release);

//clean up attachments in database
Expand All @@ -1511,6 +1519,7 @@ private void updateReleaseCompletely(Release release, User user, boolean updateC
private void updateReleaseReferencesInProjects(String mergeTargetId, String mergeSourceId, User sessionUser) throws TException {
ProjectService.Iface projectClient = new ThriftClients().makeProjectClient();

final String userEmail = sessionUser.getEmail();
Set<Project> projects = projectClient.searchByReleaseId(mergeSourceId, sessionUser);
for(Project project : projects) {
// retrieve full document, other method only retrieves summary
Expand All @@ -1521,9 +1530,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);
}
}
Expand Down Expand Up @@ -1629,7 +1639,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
Expand Down Expand Up @@ -1677,11 +1687,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

Expand All @@ -1707,7 +1717,7 @@ public RequestStatus deleteRelease(String id, User user) throws SW360Exception {
spdxDocumentDatabaseHandler.deleteSPDXDocument(spdxId, user);
release = releaseRepository.get(id);
}
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,
Expand Down Expand Up @@ -2250,8 +2260,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,
Expand Down Expand Up @@ -2691,6 +2702,7 @@ private void updateReleaseAfterComponentSplit(Component srcComponentFromDB, Comp
List<Release> srcComponentReleasesMoved = getReleasesForClearingStateSummary(srcComponentReleaseIdsMovedFromSrc);
Set<String> targetComponentReleaseVersions = targetComponentReleases.stream().map(Release::getVersion)
.collect(Collectors.toSet());
final String userEmail = user.getEmail();

List<Release> releasesToUpdate = srcComponentReleasesMoved.stream().map(r -> {
Release releaseBefore = r.deepCopy();
Expand All @@ -2701,7 +2713,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());
Expand All @@ -2727,4 +2740,10 @@ private void checkSuperAttachmentExists(Release release) {
});
}
}

public void sendExportSpreadsheetSuccessMail(String url, String recepient) throws TException {
mailUtil.sendMail(recepient, MailConstants.SUBJECT_SPREADSHEET_EXPORT_SUCCESS,
MailConstants.TEXT_SPREADSHEET_EXPORT_SUCCESS, SW360Constants.NOTIFICATION_CLASS_COMPONENT, "", false,
"component", url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChangeLogs> referenceDocLogList=new LinkedList<>();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1556,7 +1558,7 @@ private void flattenlinkedReleaseOfRelease(Map<String, ReleaseRelationship> rele
public void sendExportSpreadsheetSuccessMail(String url, String recepient) throws TException {
mailUtil.sendMail(recepient, MailConstants.SUBJECT_SPREADSHEET_EXPORT_SUCCESS,
MailConstants.TEXT_SPREADSHEET_EXPORT_SUCCESS, SW360Constants.NOTIFICATION_CLASS_PROJECT, "", false,
url);
"project", url);
}

private Map<String, String> createProjectCSRow(String relation, Project prj,
Expand Down
3 changes: 2 additions & 1 deletion backend/src-common/src/main/resources/sw360.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ subjectForRejectedClearingRequest= Your clearing request <%s> has been rejected
subjectForUpdatedProjectWithClearingRequest= Project <%s> with clearing request <%s> updated
subjectForSuccessfulExport = Spreadsheet Export Successful

textForSuccessfulExport = The project spreadsheet export successfully completed. Please find the download link(%s) here.
textForSuccessfulExport = The %s spreadsheet export successfully completed. Please find the download link(%s) here.
textForNewModerationRequest= a new moderation request has been added to your SW360-account.\n\n
textForUpdateModerationRequest= \
one of the moderation requests previously added to your \
Expand All @@ -83,3 +83,4 @@ enable.sw360.change.log=false
sw360changelog.output.path=sw360changelog/sw360changelog
auto.set.ecc.status=false
send.project.spreadsheet.export.to.mail.enabled=false
send.component.spreadsheet.export.to.mail.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//////////////////////////////////
Expand Down Expand Up @@ -658,4 +660,9 @@ public Map<PaginationData, List<Component>> getRecentComponentsSummaryWithPagina
PaginationData pageData) throws TException {
return handler.getRecentComponentsSummaryWithPagination(user, pageData);
}

@Override
public void sendExportSpreadsheetSuccessMail(String url, String recepient) throws TException {
handler.sendExportSpreadsheetSuccessMail(url, recepient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class PortalConstants {
public static final String CLEARING_REPORT_TEMPLATE_FORMAT;
public static final String DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS;
public static final Boolean SEND_PROJECT_SPREADSHEET_EXPORT_TO_MAIL_ENABLED;
public static final Boolean SEND_COMPONENT_SPREADSHEET_EXPORT_TO_MAIL_ENABLED;
public static final String LOAD_OPEN_MODERATION_REQUEST = "loadOpenModerationRequest";
public static final String LOAD_CLOSED_MODERATION_REQUEST = "loadClosedModerationRequest";

Expand Down Expand Up @@ -715,6 +716,7 @@ public class PortalConstants {
System.getProperty("RunComponentVisibilityRestrictionTest", props.getProperty("component.visibility.restriction.enabled", "false")));
DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS = props.getProperty("org.eclipse.sw360.disable.clearing.request.for.project.group", "");
SEND_PROJECT_SPREADSHEET_EXPORT_TO_MAIL_ENABLED = Boolean.parseBoolean(props.getProperty("send.project.spreadsheet.export.to.mail.enabled", "false"));
SEND_COMPONENT_SPREADSHEET_EXPORT_TO_MAIL_ENABLED = Boolean.parseBoolean(props.getProperty("send.component.spreadsheet.export.to.mail.enabled", "false"));
}

private PortalConstants() {
Expand Down
Loading

0 comments on commit 1e45b5b

Please sign in to comment.