Search in sources :

Example 51 with Component

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

the class ComponentSearchHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    assumeCanConnectTo(ThriftClients.BACKEND_URL + "/couchdblucene/");
    components = new ArrayList<>();
    Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setCreatedBy(email1);
    component1.addToLanguages("C");
    component1.addToCategories("library");
    component1.addToOperatingSystems("linux");
    component1.addToSoftwarePlatforms("boost");
    component1.addToReleaseIds("R1A");
    component1.addToReleaseIds("R1B");
    component1.addToVendorNames("V1");
    components.add(component1);
    Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setCreatedBy(email2);
    component2.addToLanguages("D");
    component2.addToLanguages("C");
    component2.addToCategories("test");
    component2.addToOperatingSystems("test");
    component2.addToSoftwarePlatforms("test");
    component2.addToReleaseIds("R2A");
    component2.addToReleaseIds("R2B");
    component2.addToReleaseIds("R2C");
    component1.addToVendorNames("V2");
    components.add(component2);
    Component component3 = new Component().setId("C3").setName("component3").setDescription("d3").setCreatedBy(email1);
    component3.addToSubscribers(email1);
    component3.addToLanguages("E");
    components.add(component3);
    // Create the database
    TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
    // Prepare the database
    DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
    for (Component component : components) {
        databaseConnector.add(component);
    }
    // Prepare the handler
    searchHandler = new ComponentSearchHandler(DatabaseSettings.getConfiguredHttpClient(), dbName);
}
Also used : DatabaseConnector(org.eclipse.sw360.datahandler.couchdb.DatabaseConnector) Component(org.eclipse.sw360.datahandler.thrift.components.Component) ComponentSearchHandler(org.eclipse.sw360.datahandler.db.ComponentSearchHandler) Before(org.junit.Before)

Example 52 with Component

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

the class ProjectDatabaseHandler method getReleaseClearingStatuses.

public List<ReleaseClearingStatusData> getReleaseClearingStatuses(String projectId, User user) throws SW360Exception {
    Project project = getProjectById(projectId, user);
    SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdsToProject = releaseIdToProjects(project, user);
    List<Release> releasesById = componentDatabaseHandler.getFullReleases(releaseIdsToProject.keySet());
    Map<String, Component> componentsById = ThriftUtils.getIdMap(componentDatabaseHandler.getComponentsShort(releasesById.stream().map(Release::getComponentId).collect(Collectors.toSet())));
    List<ReleaseClearingStatusData> releaseClearingStatuses = new ArrayList<>();
    for (Release release : releasesById) {
        List<String> projectNames = new ArrayList<>();
        List<String> mainlineStates = new ArrayList<>();
        for (ProjectWithReleaseRelationTuple projectWithReleaseRelation : releaseIdsToProject.get(release.getId())) {
            projectNames.add(printName(projectWithReleaseRelation.getProject()));
            mainlineStates.add(ThriftEnumUtils.enumToString(projectWithReleaseRelation.getRelation().getMainlineState()));
            if (projectNames.size() > 3) {
                projectNames.add("...");
                mainlineStates.add("...");
                break;
            }
        }
        releaseClearingStatuses.add(new ReleaseClearingStatusData(release).setProjectNames(joinStrings(projectNames)).setMainlineStates(joinStrings(mainlineStates)).setComponentType(componentsById.get(release.getComponentId()).getComponentType()));
    }
    return releaseClearingStatuses;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectWithReleaseRelationTuple(org.eclipse.sw360.datahandler.thrift.projects.ProjectWithReleaseRelationTuple)

Example 53 with Component

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

the class ComponentDatabaseHandler method getComponentForEdit.

public Component getComponentForEdit(String id, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    Component component = getComponent(id, user);
    DocumentState documentState;
    if (moderationRequestsForDocumentId.isEmpty()) {
        documentState = CommonUtils.getOriginalDocumentState();
    } else {
        final String email = user.getEmail();
        Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
        if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
            ModerationRequest moderationRequest = moderationRequestOptional.get();
            component = moderator.updateComponentFromModerationRequest(component, moderationRequest.getComponentAdditions(), moderationRequest.getComponentDeletions());
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    component.setPermissions(makePermission(component, user).getPermissionMap());
    component.setDocumentState(documentState);
    return component;
}
Also used : ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 54 with Component

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

the class ComponentPortlet method prepareReleaseEdit.

private void prepareReleaseEdit(RenderRequest request, RenderResponse response) throws PortletException {
    String id = request.getParameter(COMPONENT_ID);
    String releaseId = request.getParameter(RELEASE_ID);
    final User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_RELEASE);
    if (isNullOrEmpty(id) && isNullOrEmpty(releaseId)) {
        throw new PortletException("Component or Release ID not set!");
    }
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        Release release;
        if (!isNullOrEmpty(releaseId)) {
            release = client.getReleaseByIdForEdit(releaseId, user);
            request.setAttribute(RELEASE, release);
            request.setAttribute(DOCUMENT_ID, releaseId);
            setAttachmentsInRequest(request, release.getAttachments());
            putDirectlyLinkedReleaseRelationsInRequest(request, release);
            Map<RequestedAction, Boolean> permissions = release.getPermissions();
            DocumentState documentState = release.getDocumentState();
            setUsingDocs(request, releaseId, user, client);
            addEditDocumentMessage(request, permissions, documentState);
            if (isNullOrEmpty(id)) {
                id = release.getComponentId();
            }
        } else {
            release = (Release) request.getAttribute(RELEASE);
            if (release == null) {
                release = new Release();
                release.setComponentId(id);
                release.setClearingState(ClearingState.NEW_CLEARING);
                request.setAttribute(RELEASE, release);
                putDirectlyLinkedReleaseRelationsInRequest(request, release);
                setAttachmentsInRequest(request, release.getAttachments());
                setUsingDocs(request, null, user, client);
                SessionMessages.add(request, "request_processed", "New Release");
            }
        }
        Component component = client.getComponentById(id, user);
        addComponentBreadcrumb(request, response, component);
        if (!isNullOrEmpty(release.getId())) {
            // Otherwise the link is meaningless
            addReleaseBreadcrumb(request, response, release);
        }
        request.setAttribute(COMPONENT, component);
        request.setAttribute(IS_USER_AT_LEAST_ECC_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.ECC_ADMIN, user) ? "Yes" : "No");
    } catch (TException e) {
        log.error("Error fetching release from backend!", e);
        setSW360SessionError(request, ErrorMessages.ERROR_GETTING_RELEASE);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction)

Example 55 with Component

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

the class ComponentPortlet method prepareComponentMerge.

private void prepareComponentMerge(RenderRequest request, RenderResponse response) throws PortletException {
    final User user = UserCacheHolder.getUserFromRequest(request);
    String componentId = request.getParameter(COMPONENT_ID);
    if (isNullOrEmpty(componentId)) {
        throw new PortletException("Component ID not set!");
    }
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        Component component = client.getComponentById(componentId, user);
        request.setAttribute(COMPONENT, component);
        addComponentBreadcrumb(request, response, component);
        PortletURL mergeUrl = response.createRenderURL();
        mergeUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_MERGE_COMPONENT);
        mergeUrl.setParameter(PortalConstants.COMPONENT_ID, componentId);
        addBreadcrumbEntry(request, "Merge", mergeUrl);
    } catch (TException e) {
        log.error("Error fetching release from backend!", e);
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL)

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