Skip to content

Commit

Permalink
Merge pull request #1539 from siemens/feat/ModifiedOnAndModifiedByFie…
Browse files Browse the repository at this point in the history
…lds-1479

feat(UI): ModifiedOn & MOdifiedBy fields for Project/COmponent/Release

Reviewed by: smruti.sahoo@siemens.com, kouki1.hama@toshiba.co.jp
Tested by: kumar.nikesh@siemens.com
  • Loading branch information
ag4ums authored Jun 18, 2022
2 parents 7b34492 + 709a5ec commit 4678016
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 19 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 @@ -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());
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);

Expand Down Expand Up @@ -891,6 +894,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 @@ -909,7 +913,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 @@ -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());
Expand Down Expand Up @@ -1001,10 +1006,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 @@ -1234,9 +1240,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 @@ -1465,6 +1472,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 @@ -1479,6 +1487,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 @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2466,6 +2477,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 @@ -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());
Expand Down
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
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
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 @@ -130,13 +130,27 @@
</core_rt:choose>

<tr>
<td colspan="3">
<td >
<div class="form-group">
<label for="comp_desc"><liferay-ui:message key="short.description" /></label>
<textarea class="form-control" id="comp_desc" name="<portlet:namespace/><%=Component._Fields.DESCRIPTION%>" rows="4"
<textarea class="form-control" id="comp_desc" name="<portlet:namespace/><%=Component._Fields.DESCRIPTION%>" rows="3"
placeholder="<liferay-ui:message key="enter.description" />"><sw360:out value="${component.description}"/></textarea>
</div>
</td>
<td>
<div class="form-group">
<label for="modified_on"><liferay-ui:message key="modified.on" /></label>
<input id="modified_on" name="<portlet:namespace/><%=Component._Fields.MODIFIED_ON%>" type="date"
placeholder="<liferay-ui:message key="modified.date.yyyy.mm.dd" />"
value="<sw360:out value="${component.modifiedOn}"/>" readonly class="form-control"/>
</div>
</td>
<td>
<div class="form-group">
<sw360:DisplayUserEdit email="${component.modifiedBy}" id="<%=Component._Fields.MODIFIED_BY.toString()%>"
description="modified.by" multiUsers="false" readonly="true"/>
</div>
</td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
<td><liferay-ui:message key="categories" />:</td>
<td><sw360:DisplayCollection value="${component.categories}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.on" />:</td>
<td><sw360:out value="${component.modifiedOn}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.by" />:</td>
<td><sw360:DisplayUserEmail email="${component.modifiedBy}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="component.type" />:</td>
<td><sw360:DisplayEnum value="${component.componentType}"/></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,25 @@
description="moderators" multiUsers="true" readonly="false"/>
</td>
</tr>

<tr>
<td>
<div class="form-group">
<label for="modified_on"><liferay-ui:message key="modified.on" /></label>
<input id="modified_on" name="<portlet:namespace/><%=Release._Fields.MODIFIED_ON%>" type="date"
placeholder="<liferay-ui:message key="modified.date.yyyy.mm.dd" />"
value="<sw360:out value="${release.modifiedOn}"/>" readonly class="form-control"/>
</div>
</td>
<td>
<div class="form-group">
<sw360:DisplayUserEdit email="${release.modifiedBy}" id="<%=Release._Fields.MODIFIED_BY.toString()%>"
description="modified.by" multiUsers="false" readonly="true"/>
</div>
</td>
<td>
</td>
</tr>
</table>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<td><liferay-ui:message key="created.by" />:</td>
<td><sw360:DisplayUserEmail email="${release.createdBy}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.on" />:</td>
<td><sw360:out value="${release.modifiedOn}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.by" />:</td>
<td><sw360:DisplayUserEmail email="${release.modifiedBy}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="contributors" />:</td>
<td><sw360:DisplayUserEmailCollection value="${release.contributors}"/></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@
<sw360:DisplayVendorEdit id="<%=Project._Fields.VENDOR_ID.toString()%>" vendor="${project.vendor}" label="vendor"/>
</td>
</tr>
<tr>
<td>
<div class="form-group">
<label for="modified_on"><liferay-ui:message key="modified.on" /></label>
<input id="modified_on" name="<portlet:namespace/><%=Project._Fields.MODIFIED_ON%>" type="date"
placeholder="<liferay-ui:message key="modified.date.yyyy.mm.dd" />"
value="<sw360:out value="${project.modifiedOn}"/>" readonly class="form-control"/>
</div>
</td>
<td>
<div class="form-group">
<sw360:DisplayUserEdit email="${project.modifiedBy}" id="<%=Project._Fields.MODIFIED_BY.toString()%>"
description="modified.by" multiUsers="false" readonly="true"/>
</div>
</td>
<td>
</td>
</tr>
<tr>
<td>
<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
<td><liferay-ui:message key="created.by" />:</td>
<td><sw360:DisplayUserEmail email="${project.createdBy}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.on" />:</td>
<td><sw360:out value="${project.modifiedOn}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="modified.by" />:</td>
<td><sw360:DisplayUserEmail email="${project.modifiedBy}"/></td>
</tr>
<tr>
<td><liferay-ui:message key="project.type" />:</td>
<td><sw360:DisplayEnum value="${project.projectType}"/></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ moderator=Moderator
moderators=Moderators
modified=Modified
modified.by=Modified By
modified.date.yyyy.mm.dd=Modified date YYYY-MM-DD
modified.on=Modified On
monotone=Monotone
more.info=More Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ moderator=モデレータ
moderators=モデレータ
modified=改造
modified.by=変更方法
modified.date.yyyy.mm.dd=Modified date YYYY-MM-DD
modified.on=変更された
monotone=Monotone
more.info=詳細情報
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ moderator=Người kiểm duyệt
moderators=Người kiểm duyệt
modified=Sửa đổi
modified.by=Sửa đổi bởi
modified.date.yyyy.mm.dd=Modified date YYYY-MM-DD
modified.on=Đã sửa đổi
monotone=Giọng bằng bằng
more.info=Thêm thông tin
Expand Down
Loading

0 comments on commit 4678016

Please sign in to comment.