Search in sources :

Example 6 with ModerationRequest

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;
            }
        }
    }
}
Also used : ModerationService(org.eclipse.sw360.datahandler.thrift.moderation.ModerationService) TException(org.apache.thrift.TException) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) User(org.eclipse.sw360.datahandler.thrift.users.User) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 7 with ModerationRequest

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;
}
Also used : COTSDetails(org.eclipse.sw360.datahandler.thrift.components.COTSDetails)

Example 8 with ModerationRequest

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;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 9 with ModerationRequest

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;
}
Also used : TException(org.apache.thrift.TException) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest) Component(org.eclipse.sw360.datahandler.thrift.components.Component) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 10 with ModerationRequest

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);
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Aggregations

ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)24 TException (org.apache.thrift.TException)11 User (org.eclipse.sw360.datahandler.thrift.users.User)8 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Component (org.eclipse.sw360.datahandler.thrift.components.Component)4 ModerationService (org.eclipse.sw360.datahandler.thrift.moderation.ModerationService)4 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 License (org.eclipse.sw360.datahandler.thrift.licenses.License)3 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Organization (com.liferay.portal.model.Organization)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 THttpClient (org.apache.thrift.transport.THttpClient)1 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)1 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)1 DocumentState (org.eclipse.sw360.datahandler.thrift.DocumentState)1 COTSDetails (org.eclipse.sw360.datahandler.thrift.components.COTSDetails)1 LicenseService (org.eclipse.sw360.datahandler.thrift.licenses.LicenseService)1 Obligation (org.eclipse.sw360.datahandler.thrift.licenses.Obligation)1