Search in sources :

Example 11 with ModerationRequest

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

Example 12 with ModerationRequest

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

Example 13 with ModerationRequest

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

Example 14 with ModerationRequest

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

Example 15 with ModerationRequest

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

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