Search in sources :

Example 26 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class AttachmentStreamConnectorTest method testGetConcatenatedStreamReadThrowsOnNonExistent.

@Test
public void testGetConcatenatedStreamReadThrowsOnNonExistent() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.isOnlyRemote()).thenReturn(false);
    when(attachment.isSetPartsCount()).thenReturn(true);
    when(attachment.getPartsCount()).thenReturn("2");
    when(attachment.getFilename()).thenReturn("fil");
    String attachmentId = "id";
    when(attachment.getId()).thenReturn(attachmentId);
    AttachmentInputStream part1 = mock(AttachmentInputStream.class);
    when(connector.getAttachment(attachmentId, "fil_part1")).thenReturn(part1);
    when(connector.getAttachment(attachmentId, "fil_part2")).thenThrow(new DocumentNotFoundException(""));
    when(part1.read()).thenReturn(1, -1);
    InputStream attachmentStream = attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentId))));
    assertThat(attachmentStream.read(), is(1));
    try {
        assertThat(attachmentStream.read(), is(2));
        fail("expected Exception not thrown");
    } catch (IOException ignored) {
    }
    verify(part1).close();
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) DocumentNotFoundException(org.ektorp.DocumentNotFoundException) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) AttachmentInputStream(org.ektorp.AttachmentInputStream) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class AttachmentStreamConnectorTest method testGetFullStream.

@Test
public void testGetFullStream() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.isOnlyRemote()).thenReturn(false);
    when(attachment.isSetPartsCount()).thenReturn(false);
    when(attachment.getFilename()).thenReturn("fil");
    String attachmentId = "id";
    when(attachment.getId()).thenReturn(attachmentId);
    AttachmentInputStream full = mock(AttachmentInputStream.class);
    when(connector.getAttachment(attachmentId, "fil")).thenReturn(full);
    when(full.read()).thenReturn(1, 2, -1);
    InputStream attachmentStream = attachmentStreamConnector.getAttachmentStream(attachment, dummyUser, new Project().setVisbility(Visibility.ME_AND_MODERATORS).setCreatedBy(dummyUser.getEmail()).setAttachments(Collections.singleton(new Attachment().setAttachmentContentId(attachmentId))));
    assertThat(attachmentStream.read(), is(1));
    assertThat(attachmentStream.read(), is(2));
    assertThat(attachmentStream.read(), is(-1));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) AttachmentInputStream(org.ektorp.AttachmentInputStream) InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) AttachmentInputStream(org.ektorp.AttachmentInputStream) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 28 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class ModerationPortlet method renderProjectModeration.

public void renderProjectModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
    final boolean requestDocumentDelete = moderationRequest.isRequestDocumentDelete();
    Boolean is_used = false;
    Project actual_project = null;
    try {
        ProjectService.Iface client = thriftClients.makeProjectClient();
        actual_project = client.getProjectById(moderationRequest.getDocumentId(), user);
        actual_project = client.fillClearingStateSummary(Collections.singletonList(actual_project), user).get(0);
        is_used = client.projectIsUsed(actual_project.getId());
        request.setAttribute(PortalConstants.ACTUAL_PROJECT, actual_project);
        request.setAttribute(PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT, getDefaultLicenseInfoHeaderText());
    } catch (TException e) {
        log.error("Could not retrieve project", e);
    }
    if (actual_project == null) {
        renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
        return;
    }
    if (refuseToDeleteUsedDocument(request, response, moderationRequest, user, requestDocumentDelete, is_used))
        return;
    prepareProject(request, user, actual_project);
    if (moderationRequest.isRequestDocumentDelete()) {
        include("/html/moderation/projects/delete.jsp", request, response);
    } else {
        // updateProjectFromModerationRequest and add updated project to request.
        include("/html/moderation/projects/merge.jsp", request, response);
    }
}
Also used : TException(org.apache.thrift.TException) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService)

Example 29 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project 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 30 with Project

use of org.eclipse.sw360.datahandler.thrift.projects.Project in project sw360portal by sw360.

the class ProjectImportPortlet method updateImportables.

private void updateImportables(JSONObject responseData, LoginState loginState, RemoteCredentials remoteCredentials, String projectName) throws JsonProcessingException {
    if (!nullToEmpty(remoteCredentials.getServerUrl()).isEmpty()) {
        List<Project> importables = loadImportables(remoteCredentials, projectName);
        JSONArray serializedProjects = JSONFactoryUtil.createJSONArray();
        for (Project p : importables) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
            if (p.isSetExternalIds() && !isNullOrEmpty(p.getExternalIds().get(getIdName())))
                jsonObject.put("externalId", p.getExternalIds().get(getIdName()));
            jsonObject.put("name", p.getName());
            serializedProjects.put(jsonObject.toString());
        }
        responseData.put(ProjectImportConstants.RESPONSE__NEW_IMPORTABLES, serializedProjects);
    }
    responseData.put(ProjectImportConstants.RESPONSE__DB_URL, remoteCredentials.getServerUrl());
    loginState.login(remoteCredentials.getServerUrl());
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) JSONObject(com.liferay.portal.kernel.json.JSONObject) JSONArray(com.liferay.portal.kernel.json.JSONArray)

Aggregations

Project (org.eclipse.sw360.datahandler.thrift.projects.Project)87 User (org.eclipse.sw360.datahandler.thrift.users.User)46 Test (org.junit.Test)42 TException (org.apache.thrift.TException)27 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)16 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)15 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)12 Release (org.eclipse.sw360.datahandler.thrift.components.Release)12 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)10 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)7 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)7 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)6 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 HashSet (java.util.HashSet)5 ResponseEntity (org.springframework.http.ResponseEntity)5