Search in sources :

Example 1 with SW360Utils.printName

use of org.eclipse.sw360.datahandler.common.SW360Utils.printName in project sw360portal by sw360.

the class ComponentPortlet method generateComponentMergeWizardStep0Response.

private void generateComponentMergeWizardStep0Response(ActionRequest request, JsonGenerator jsonGenerator) throws IOException, TException {
    User sessionUser = UserCacheHolder.getUserFromRequest(request);
    ComponentService.Iface cClient = thriftClients.makeComponentClient();
    List<Component> componentSummary = cClient.getComponentSummary(sessionUser);
    jsonGenerator.writeStartObject();
    jsonGenerator.writeArrayFieldStart("components");
    componentSummary.stream().forEach(component -> {
        try {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("id", component.getId());
            jsonGenerator.writeStringField("name", SW360Utils.printName(component));
            jsonGenerator.writeStringField("createdBy", component.getCreatedBy());
            jsonGenerator.writeNumberField("releases", component.getReleaseIdsSize());
            jsonGenerator.writeEndObject();
        } catch (IOException e) {
            log.error("An error occurred while generating wizard response", e);
        }
    });
    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) IOException(java.io.IOException)

Example 2 with SW360Utils.printName

use of org.eclipse.sw360.datahandler.common.SW360Utils.printName 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 3 with SW360Utils.printName

use of org.eclipse.sw360.datahandler.common.SW360Utils.printName 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 4 with SW360Utils.printName

use of org.eclipse.sw360.datahandler.common.SW360Utils.printName 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 5 with SW360Utils.printName

use of org.eclipse.sw360.datahandler.common.SW360Utils.printName 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)

Aggregations

ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)5 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Component (org.eclipse.sw360.datahandler.thrift.components.Component)2 IOException (java.io.IOException)1 TException (org.apache.thrift.TException)1 Release (org.eclipse.sw360.datahandler.thrift.components.Release)1 License (org.eclipse.sw360.datahandler.thrift.licenses.License)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 User (org.eclipse.sw360.datahandler.thrift.users.User)1