use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationPortlet method renderEditViewForId.
private void renderEditViewForId(RenderRequest request, RenderResponse response, String id) throws IOException, PortletException, TException {
if (id != null) {
ModerationRequest moderationRequest = null;
User user = UserCacheHolder.getUserFromRequest(request);
try {
ModerationService.Iface client = thriftClients.makeModerationClient();
moderationRequest = client.getModerationRequestById(id);
boolean actionsAllowed = moderationRequest.getModerators().contains(user.getEmail()) && ModerationPortletUtils.isOpenModerationRequest(moderationRequest);
request.setAttribute(PortalConstants.MODERATION_ACTIONS_ALLOWED, actionsAllowed);
if (actionsAllowed) {
SessionMessages.add(request, "request_processed", "You have assigned yourself to this moderation request.");
client.setInProgress(id, user);
}
request.setAttribute(PortalConstants.MODERATION_REQUEST, moderationRequest);
addModerationBreadcrumb(request, response, moderationRequest);
} catch (TException e) {
log.error("Error fetching moderation details from backend", e);
}
if (moderationRequest != null) {
switch(moderationRequest.getDocumentType()) {
case COMPONENT:
renderComponentModeration(request, response, moderationRequest, user);
break;
case RELEASE:
VendorService.Iface vendorClient = thriftClients.makeVendorClient();
Release additions = moderationRequest.getReleaseAdditions();
if (additions.isSetVendorId()) {
additions.setVendor(vendorClient.getByID(additions.getVendorId()));
}
Release deletions = moderationRequest.getReleaseDeletions();
if (deletions.isSetVendorId()) {
deletions.setVendor(vendorClient.getByID(deletions.getVendorId()));
}
renderReleaseModeration(request, response, moderationRequest, user);
break;
case PROJECT:
renderProjectModeration(request, response, moderationRequest, user);
break;
case LICENSE:
renderLicenseModeration(request, response, moderationRequest, user);
break;
case USER:
renderUserModeration(request, response, moderationRequest, user);
break;
}
}
}
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class COTSDetailsModerationRequestGenerator method setAdditionsAndDeletions.
@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, COTSDetails update, COTSDetails actual) {
updateDocument = update == null ? new COTSDetails() : update;
actualDocument = actual == null ? new COTSDetails() : actual;
documentAdditions = null;
documentDeletions = null;
for (COTSDetails._Fields field : COTSDetails._Fields.values()) {
if (COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.BOOL || COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.I32) {
if (actualDocument.getFieldValue(field) != updateDocument.getFieldValue(field)) {
if (documentAdditions == null) {
documentAdditions = new COTSDetails();
}
if (documentDeletions == null) {
documentDeletions = new COTSDetails();
}
documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
}
continue;
}
if (COTSDetails.metaDataMap.get(field).valueMetaData.type == TType.STRING) {
if (isNullOrEmpty((String) actualDocument.getFieldValue(field)) && isNullOrEmpty((String) updateDocument.getFieldValue(field))) {
continue;
}
if (actualDocument.isSet(field) && !updateDocument.isSet(field)) {
if (documentDeletions == null) {
documentDeletions = new COTSDetails();
}
documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
continue;
}
if (updateDocument.isSet(field) && !actualDocument.isSet(field)) {
if (documentAdditions == null) {
documentAdditions = new COTSDetails();
}
documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
continue;
}
if (!(actualDocument.getFieldValue(field).equals(updateDocument.getFieldValue(field)))) {
if (documentAdditions == null) {
documentAdditions = new COTSDetails();
}
if (documentDeletions == null) {
documentDeletions = new COTSDetails();
}
documentAdditions.setFieldValue(field, updateDocument.getFieldValue(field));
documentDeletions.setFieldValue(field, actualDocument.getFieldValue(field));
}
}
}
request.getReleaseAdditions().setCotsDetails(documentAdditions);
request.getReleaseDeletions().setCotsDetails(documentDeletions);
return request;
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ComponentModerationRequestGenerator method setAdditionsAndDeletions.
@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, Component updateComponent, Component actualComponent) {
updateDocument = updateComponent;
actualDocument = actualComponent;
documentAdditions = new Component();
documentDeletions = new Component();
// required fields:
documentAdditions.setName(updateComponent.getName());
documentAdditions.setId(actualComponent.getId());
documentDeletions.setName(actualComponent.getName());
documentDeletions.setId(actualComponent.getId());
for (Component._Fields field : Component._Fields.values()) {
if (actualComponent.getFieldValue(field) == null) {
documentAdditions.setFieldValue(field, updateComponent.getFieldValue(field));
} else if (updateComponent.getFieldValue(field) == null) {
documentDeletions.setFieldValue(field, actualComponent.getFieldValue(field));
} else if (!actualComponent.getFieldValue(field).equals(updateComponent.getFieldValue(field))) {
switch(field) {
// ignored fields
case PERMISSIONS:
case DOCUMENT_STATE:
// releases and related fields are not updated via moderation requests
case RELEASES:
case RELEASE_IDS:
case MAIN_LICENSE_IDS:
case LANGUAGES:
case OPERATING_SYSTEMS:
case VENDOR_NAMES:
break;
case ATTACHMENTS:
dealWithAttachments(Component._Fields.ATTACHMENTS);
break;
case ROLES:
dealWithCustomMap(Component._Fields.ROLES);
break;
default:
dealWithBaseTypes(field, Component.metaDataMap.get(field));
}
}
}
request.setComponentAdditions(documentAdditions);
request.setComponentDeletions(documentDeletions);
return request;
}
use of org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest in project sw360portal by sw360.
the class ModerationDatabaseHandler method createRequest.
public RequestStatus createRequest(Component component, User user, Boolean isDeleteRequest) {
Component dbcomponent;
try {
dbcomponent = componentDatabaseHandler.getComponent(component.getId(), user);
} catch (SW360Exception e) {
log.error("Could not get original component from database. Could not generate moderation request.", e);
return RequestStatus.FAILURE;
}
// Define moderators
Set<String> moderators = new HashSet<>();
CommonUtils.add(moderators, dbcomponent.getCreatedBy());
try {
String department = getDepartmentByUserEmail(component.getCreatedBy());
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.CLEARING_ADMIN, department));
} catch (TException e) {
log.error("Could not get user from database. Clearing admins not added as moderators, since department is missing.");
}
CommonUtils.addAll(moderators, getUsersAtLeast(UserGroup.ADMIN));
ModerationRequest request = createStubRequest(user, isDeleteRequest, component.getId(), moderators);
// Set meta-data
request.setDocumentType(DocumentType.COMPONENT);
request.setDocumentName(SW360Utils.printName(dbcomponent));
// Fill the request
ModerationRequestGenerator generator = new ComponentModerationRequestGenerator();
request = generator.setAdditionsAndDeletions(request, component, dbcomponent);
if (component.isSetComponentType()) {
request.setComponentType(component.getComponentType());
}
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 acceptRequest.
public void acceptRequest(ModerationRequest request, String moderationComment, String reviewer) {
ModerationRequest dbRequest = repository.get(request.getId());
// now deleted MR anyways
if (dbRequest != null) {
dbRequest.setModerationState(ModerationState.APPROVED);
dbRequest.setTimestampOfDecision(System.currentTimeMillis());
dbRequest.setReviewer(reviewer);
dbRequest.setCommentDecisionModerator(moderationComment);
repository.update(dbRequest);
}
sendMailNotificationsForAcceptedRequest(request);
}
Aggregations