use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(License license, User user) {
License dblicense;
try {
dblicense = licenseDatabaseHandler.getLicenseForOrganisation(license.getId(), user.getDepartment());
} catch (SW360Exception e) {
log.error("Could not get original license from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = getLicenseModerators(user.getDepartment());
ModerationRequest request = createStubRequest(user, false, license.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.LICENSE);
request.setDocumentName(SW360Utils.printName(license));
// Fill the request
ModerationRequestGenerator generator = new LicenseModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, license, dblicense);
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseModerationRequestGenerator method setAdditionsAndDeletions.
@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, License updateLicense, License actualLicense) {
updateDocument = updateLicense;
actualDocument = actualLicense;
documentAdditions = new License();
documentDeletions = new License();
// required fields:
documentAdditions.setFullname(updateLicense.getFullname());
documentAdditions.setId(actualLicense.getId());
documentDeletions.setFullname(actualLicense.getFullname());
documentDeletions.setId(actualLicense.getId());
Map<String, Todo> actualTodos = Maps.uniqueIndex(nullToEmptyList(actualLicense.getTodos()), Todo::getId);
for (Todo updateTodo : updateLicense.getTodos()) {
if (!actualTodos.containsKey(updateTodo.getId())) {
if (!documentAdditions.isSetTodos()) {
documentAdditions.setTodos(new ArrayList<>());
}
documentAdditions.getTodos().add(updateTodo);
} else {
Todo actualTodo = actualTodos.get(updateTodo.getId());
Set<String> actualWhitelist = actualTodo.whitelist != null ? actualTodo.whitelist : new HashSet<String>();
Set<String> updateWhitelist = updateTodo.whitelist != null ? updateTodo.whitelist : new HashSet<String>();
String departement = request.getRequestingUserDepartment();
if (updateWhitelist.contains(departement) && !actualWhitelist.contains(departement)) {
if (!documentAdditions.isSetTodos()) {
documentAdditions.setTodos(new ArrayList<>());
}
documentAdditions.getTodos().add(updateTodo);
} else if (!updateWhitelist.contains(departement) && actualWhitelist.contains(departement)) {
if (!documentDeletions.isSetTodos()) {
documentDeletions.setTodos(new ArrayList<>());
}
documentDeletions.getTodos().add(actualTodo);
}
}
}
request.setLicenseAdditions(documentAdditions);
request.setLicenseDeletions(documentDeletions);
return request;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseInfoHandler method getLicenseInfoForAttachment.
@Override
public List<LicenseInfoParsingResult> getLicenseInfoForAttachment(Release release, String attachmentContentId, User user) throws TException {
if (release == null) {
return Collections.singletonList(noSourceParsingResult(MSG_NO_RELEASE_GIVEN));
}
List<LicenseInfoParsingResult> cachedResults = licenseInfoCache.getIfPresent(attachmentContentId);
if (cachedResults != null) {
return cachedResults;
}
Attachment attachment = nullToEmptySet(release.getAttachments()).stream().filter(a -> a.getAttachmentContentId().equals(attachmentContentId)).findFirst().orElseThrow(() -> {
String message = String.format("Attachment selected for license info generation is not found in release's attachments. Release id: %s. Attachment content id: %s", release.getId(), attachmentContentId);
return new IllegalStateException(message);
});
try {
List<LicenseInfoParser> applicableParsers = parsers.stream().filter(parser -> wrapTException(() -> parser.isApplicableTo(attachment, user, release))).collect(Collectors.toList());
if (applicableParsers.size() == 0) {
LOGGER.warn("No applicable parser has been found for the attachment selected for license information");
return assignReleaseToLicenseInfoParsingResult(assignFileNameToLicenseInfoParsingResult(noSourceParsingResult("No applicable parser has been found for the attachment"), attachment.getFilename()), release);
} else if (applicableParsers.size() > 1) {
LOGGER.info("More than one parser claims to be able to parse attachment with contend id " + attachmentContentId);
}
List<LicenseInfoParsingResult> results = applicableParsers.stream().map(parser -> wrapTException(() -> parser.getLicenseInfos(attachment, user, release))).flatMap(Collection::stream).collect(Collectors.toList());
filterEmptyLicenses(results);
results = assignReleaseToLicenseInfoParsingResults(results, release);
licenseInfoCache.put(attachmentContentId, results);
return results;
} catch (WrappedTException exception) {
throw exception.getCause();
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseDatabaseHandler method updateLicenseFromInputLicense.
private License updateLicenseFromInputLicense(License license, License inputLicense, String businessUnit, User user) {
if (inputLicense.isSetTodos()) {
for (Todo todo : inputLicense.getTodos()) {
if (isTemporaryTodo(todo)) {
todo.unsetId();
try {
String todoDatabaseId = addTodo(todo, user);
license.addToTodoDatabaseIds(todoDatabaseId);
} catch (SW360Exception e) {
log.error("Error adding todo to database.");
}
} else if (todo.isSetId()) {
Todo dbTodo = todoRepository.get(todo.id);
if (todo.whitelist.contains(businessUnit) && !dbTodo.whitelist.contains(businessUnit)) {
dbTodo.addToWhitelist(businessUnit);
todoRepository.update(dbTodo);
}
if (!todo.whitelist.contains(businessUnit) && dbTodo.whitelist.contains(businessUnit)) {
dbTodo.whitelist.remove(businessUnit);
todoRepository.update(dbTodo);
}
}
}
}
license.setText(inputLicense.getText());
license.setFullname(inputLicense.getFullname());
// only a new license gets its id from the shortname. Id of an existing license isn't supposed to be changed anyway
if (!license.isSetId())
license.setId(inputLicense.getShortname());
license.unsetShortname();
license.setLicenseTypeDatabaseId(inputLicense.getLicenseTypeDatabaseId());
license.unsetLicenseType();
license.setGPLv2Compat(Optional.ofNullable(inputLicense.getGPLv2Compat()).orElse(Ternary.UNDEFINED));
license.setGPLv3Compat(Optional.ofNullable(inputLicense.getGPLv3Compat()).orElse(Ternary.UNDEFINED));
license.setExternalLicenseLink(inputLicense.getExternalLicenseLink());
return license;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseDatabaseHandler method getLicenseForOrganisationWithOwnModerationRequests.
public License getLicenseForOrganisationWithOwnModerationRequests(String id, String organisation, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
License license = getLicenseForOrganisation(id, organisation);
DocumentState documentState;
if (moderationRequestsForDocumentId.isEmpty()) {
documentState = CommonUtils.getOriginalDocumentState();
} else {
final String email = user.getEmail();
Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
ModerationRequest moderationRequest = moderationRequestOptional.get();
license = moderator.updateLicenseFromModerationRequest(license, moderationRequest.getLicenseAdditions(), moderationRequest.getLicenseDeletions(), organisation);
for (Todo todo : license.getTodos()) {
// remove other organisations from whitelist of todo
todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
}
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
license.setPermissions(makePermission(license, user).getPermissionMap());
license.setDocumentState(documentState);
return license;
}
Aggregations