use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public void createRequest(User user) {
// Define moderators
Set<String> admins = getUsersAtLeast(UserGroup.CLEARING_ADMIN, user.getDepartment());
ModerationRequest request = createStubRequest(user, false, user.getId(), admins);
// Set meta-data
request.setDocumentType(DocumentType.USER);
request.setDocumentName(SW360Utils.printName(user));
// Set the object
request.setUser(user);
addOrUpdate(request, user);
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Release release, User user, Boolean isDeleteRequest, Function<Release, Set<String>> moderatorsProvider) {
Release dbrelease;
try {
dbrelease = componentDatabaseHandler.getRelease(release.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original release from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
Set<String> moderators = moderatorsProvider.apply(dbrelease);
ModerationRequest request = createStubRequest(user, isDeleteRequest, release.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.RELEASE);
request.setDocumentName(SW360Utils.printName(dbrelease));
// Fill the rest
SW360Utils.setVendorId(release);
SW360Utils.setVendorId(dbrelease);
ModerationRequestGenerator generator = new ReleaseModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, release, dbrelease);
try {
Component parentComponent = componentDatabaseHandler.getComponent(release.getComponentId(), user);
request.setComponentType(parentComponent.getComponentType());
} catch (SW360Exception e) {
log.error("Could not retrieve parent component type of release with ID=" + release.getId());
}
addOrUpdate(request, user);
return RequestStatus.SENT_TO_MODERATOR;
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationDatabaseHandler method createStubRequest.
private ModerationRequest createStubRequest(User user, boolean isDeleteRequest, String documentId, Set<String> moderators) {
final ModerationRequest request;
List<ModerationRequest> requestByDocumentId = getRequestByDocumentId(documentId);
Optional<ModerationRequest> firstModerationRequestOfUser = CommonUtils.getFirstModerationRequestOfUser(requestByDocumentId, user.getEmail());
if (firstModerationRequestOfUser.isPresent() && CommonUtils.isStillRelevant(firstModerationRequestOfUser.get())) {
request = firstModerationRequestOfUser.get();
} else {
request = new ModerationRequest();
request.setRequestingUser(user.getEmail());
request.setDocumentId(documentId);
}
request.setTimestamp(System.currentTimeMillis());
request.setModerationState(ModerationState.PENDING);
request.setRequestDocumentDelete(isDeleteRequest);
request.setModerators(Sets.filter(moderators, notEmptyOrNull()));
request.setRequestingUserDepartment(user.getDepartment());
fillRequestWithCommentOfUser(request, user);
;
return request;
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest 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.moderation.ModerationRequest 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;
}
Aggregations