Search in sources :

Example 31 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 32 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 33 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 34 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class CombinedCLIParser method getLicenseInfoParsingResultForExternalId.

@NotNull
private LicenseInfoParsingResult getLicenseInfoParsingResultForExternalId(AttachmentContent attachmentContent, Map<String, Release> releasesByExternalId, Map<String, Set<String>> copyrightSetsByExternalId, Map<String, Set<LicenseNameWithText>> licenseNamesWithTextsByExternalId, String extId) {
    LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
    licenseInfo.setCopyrights(copyrightSetsByExternalId.get(extId));
    licenseInfo.setLicenseNamesWithTexts(licenseNamesWithTextsByExternalId.get(extId));
    LicenseInfoParsingResult parsingResult = new LicenseInfoParsingResult().setLicenseInfo(licenseInfo);
    Release release = releasesByExternalId.get(extId);
    if (release != null) {
        parsingResult.setVendor(release.isSetVendor() ? release.getVendor().getShortname() : "");
        parsingResult.setName(release.getName());
        parsingResult.setVersion(release.getVersion());
    } else {
        parsingResult.setName("No info found for external component ID " + extId);
    }
    parsingResult.setStatus(LicenseInfoRequestStatus.SUCCESS);
    return parsingResult;
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) Release(org.eclipse.sw360.datahandler.thrift.components.Release) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class TestComponentClient method main.

public static void main(String[] args) throws TException, IOException {
    THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/components/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    ComponentService.Iface client = new ComponentService.Client(protocol);
// List<Component> components = client.getComponentSummary(user);
// List<Component> recentComponents = client.getRecentComponents();
// List<Release> releases = client.getReleaseSummary(user);
// 
// System.out.println("Fetched " + components.size() + " components from license service");
// System.out.println("Fetched " + releases.size() + " releases from license service");
// System.out.println("Fetched " + recentComponents.size() + " recent components from license service");
// 
// String referenceId =null;
// for (Component component : recentComponents) {
// if(referenceId==null) referenceId=component.getId();
// System.out.println(component.getId() + ": " + component.getName());
// }
// 
// if(referenceId!=null) {
// System.out.println(client.getComponentById(referenceId, user).toString());
// Component component = new ComponentHandler("http://localhost:5984", "sw360db", "sw360attachments").getComponentById(referenceId, user);
// System.out.println(component.toString());
// System.out.println(client.getComponentById(referenceId, user).toString());
// }
// 
// for(Release release : releases) {
// System.out.println(release.toString());
// }
// // This fails with a thrift error... debug!
// if(releases.size()>0) {
// String releaseNameStart = releases.get(0).getName().substring(0,1);
// System.out.println("The following releases start with " + releaseNameStart );
// 
// List<Release> releases1 = client.searchReleaseByName(releaseNameStart);
// for(Release release : releases1) {
// System.out.println(release.toString());
// }
// 
// }
// final Component cpe = client.getComponentForReportFromCPEId("cpe");
// System.out.println(cpe.toString());
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2