This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): automatically update ecc information if download url i…
…s set
- Loading branch information
1 parent
243ebc6
commit ed1d290
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project. | ||
* Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project. | ||
* With modifications by Bosch Software Innovations GmbH, 2016. | ||
* | ||
* SPDX-License-Identifier: EPL-1.0 | ||
|
@@ -69,10 +69,13 @@ | |
* @author [email protected] | ||
* @author [email protected] | ||
* @author [email protected] | ||
* @author [email protected] | ||
*/ | ||
public class ComponentDatabaseHandler extends AttachmentAwareDatabaseHandler { | ||
|
||
private static final Logger log = Logger.getLogger(ComponentDatabaseHandler.class); | ||
private static final String ASSESSOR_DEFAULT_GROUP = "no group"; | ||
private static final String ECC_AUTOSET_VALUE = "N"; | ||
|
||
/** | ||
* Connection to the couchDB database | ||
|
@@ -304,6 +307,9 @@ public AddDocumentRequestSummary addRelease(Release release, String user) throws | |
release.setCreatedBy(user); | ||
release.setCreatedOn(SW360Utils.getCreatedOn()); | ||
|
||
// Add default ECC options if download url is set | ||
autosetEccFieldsForReleaseWithDownloadUrl(release, user); | ||
|
||
// Add release to database | ||
releaseRepository.add(release); | ||
final String id = release.getId(); | ||
|
@@ -607,13 +613,18 @@ public RequestStatus updateRelease(Release release, User user, Iterable<Release. | |
} | ||
DocumentPermissions<Release> permissions = makePermission(actual, user); | ||
boolean hasChangesInEccFields = hasChangesInEccFields(release, actual); | ||
|
||
if (!hasChangesInEccFields && hasEmptyEccFields(release)) { | ||
autosetEccFieldsForReleaseWithDownloadUrl(release, user.getEmail()); | ||
} | ||
|
||
if ((hasChangesInEccFields && permissions.isActionAllowed(RequestedAction.WRITE_ECC)) || | ||
(!hasChangesInEccFields && permissions.isActionAllowed(RequestedAction.WRITE))) { | ||
copyFields(actual, release, immutableFields); | ||
|
||
autosetReleaseClearingState(release, actual); | ||
if (hasChangesInEccFields) { | ||
autosetEccUpdaterInfo(release, user); | ||
autosetEccUpdaterInfo(release, user.getEmail(), user.getDepartment()); | ||
} | ||
release.setAttachments( getAllAttachmentsToKeep(actual.getAttachments(), release.getAttachments()) ); | ||
releaseRepository.update(release); | ||
|
@@ -649,11 +660,34 @@ public boolean hasChangesInEccFields(Release release, Release actual) { | |
.reduce(false, Boolean::logicalOr); | ||
} | ||
|
||
private void autosetEccUpdaterInfo(Release release, User user) { | ||
public boolean hasEmptyEccFields(Release release) { | ||
EccInformation eccInformation = release.getEccInformation(); | ||
return isNullEmptyOrWhitespace(eccInformation.getAL()) && | ||
isNullEmptyOrWhitespace(eccInformation.getECCN()) && | ||
(eccInformation.getEccStatus() == null || eccInformation.getEccStatus() == ECCStatus.OPEN); | ||
} | ||
|
||
private void autosetEccUpdaterInfo(Release release, String contactPerson, String department) { | ||
ensureEccInformationIsSet(release); | ||
release.getEccInformation().setAssessmentDate(SW360Utils.getCreatedOn()); | ||
release.getEccInformation().setAssessorContactPerson(user.getEmail()); | ||
release.getEccInformation().setAssessorDepartment(user.getDepartment()); | ||
release.getEccInformation().setAssessorContactPerson(contactPerson); | ||
release.getEccInformation().setAssessorDepartment(department); | ||
} | ||
|
||
private void autosetEccFieldsForReleaseWithDownloadUrl(Release release, String contactPerson) { | ||
// For unmodified OSS, ECC classification can be done automatically: sw360/sw360portal#773 | ||
String url = release.getDownloadurl(); | ||
if (!isNullOrEmpty(url)) { | ||
if (CommonUtils.isValidUrl(url)) { | ||
autosetEccUpdaterInfo(release, contactPerson, ASSESSOR_DEFAULT_GROUP); | ||
EccInformation eccInfo = release.getEccInformation(); | ||
eccInfo.setAL(ECC_AUTOSET_VALUE); | ||
eccInfo.setECCN(ECC_AUTOSET_VALUE); | ||
eccInfo.setEccStatus(ECCStatus.APPROVED); | ||
} else { | ||
log.warn("Could not set ECC options for unmodified OSS because download url is not valid: " + url); | ||
} | ||
} | ||
} | ||
|
||
private void prepareRelease(Release release) throws SW360Exception { | ||
|
@@ -1126,7 +1160,7 @@ public Map<String, List<String>> getDuplicateReleases() { | |
|
||
public Set<Attachment> getSourceAttachments(String releaseId) throws SW360Exception { | ||
Release release = assertNotNull(releaseRepository.get(releaseId)); | ||
|
||
return nullToEmptySet(release.getAttachments()) | ||
.stream() | ||
.filter(Objects::nonNull) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters