Search in sources :

Example 66 with Component

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

the class ModerationPortlet method renderComponentModeration.

public void renderComponentModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
    final boolean requestDocumentDelete = moderationRequest.isRequestDocumentDelete();
    Boolean is_used = false;
    Component actual_component = null;
    try {
        ComponentService.Iface client = thriftClients.makeComponentClient();
        actual_component = client.getComponentById(moderationRequest.getDocumentId(), user);
        is_used = client.componentIsUsed(actual_component.getId());
    } catch (TException e) {
        log.error("Could not retrieve component", e);
    }
    if (actual_component == null) {
        renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
        return;
    }
    if (refuseToDeleteUsedDocument(request, response, moderationRequest, user, requestDocumentDelete, is_used))
        return;
    prepareComponent(request, user, actual_component);
    request.setAttribute(PortalConstants.ACTUAL_COMPONENT, actual_component);
    if (moderationRequest.isRequestDocumentDelete()) {
        include("/html/moderation/components/delete.jsp", request, response);
    } else {
        include("/html/moderation/components/merge.jsp", request, response);
    }
}
Also used : TException(org.apache.thrift.TException) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 67 with Component

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

the class ComponentUploadPortlet method generateReleaseLinksFile.

private void generateReleaseLinksFile(ResourceRequest request, ResourceResponse response) throws IOException {
    List<Iterable<String>> csvRows = new ArrayList<>();
    final List<Component> componentDetailedSummaryForExport = getComponentDetailedSummaryForExport();
    if (componentDetailedSummaryForExport != null) {
        final Map<String, Component> componentsById = ThriftUtils.getIdMap(componentDetailedSummaryForExport);
        final Map<String, Release> releasesById = getReleasesById(componentDetailedSummaryForExport);
        for (Component component : componentDetailedSummaryForExport) {
            dealWithReleaseLinksContainedInComponent(componentsById, releasesById, component, csvRows);
        }
    }
    ByteArrayInputStream byteArrayInputStream = CSVExport.createCSV(ReleaseLinkCSVRecord.getCSVHeaderIterable(), csvRows);
    PortletResponseUtil.sendFile(request, response, "ReleaseLinkInfo.csv", byteArrayInputStream, "text/csv");
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 68 with Component

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

the class VulnerabilityHandler method enrichVulnerabilityDTO.

private VulnerabilityDTO enrichVulnerabilityDTO(VulnerabilityDTO dto, LoadingCache<String, Component> componentCache, LoadingCache<String, Release> releaseCache) {
    String releaseId = dto.getIntReleaseId();
    try {
        Release release = releaseCache.get(releaseId);
        if (release != null) {
            dto.setIntComponentId(release.getComponentId());
            String releaseName = "";
            if (!StringUtils.isEmpty(release.getName())) {
                releaseName = release.getName() + " ";
                dto.setIntComponentName(release.getName());
            } else {
                Component component = componentCache.get(release.getComponentId());
                if (component != null) {
                    releaseName = component.getName() + " ";
                    dto.setIntComponentName(component.getName());
                }
            }
            dto.setIntReleaseName(releaseName + release.getVersion());
        }
    } catch (ExecutionException e) {
        log.error(e);
    }
    return dto;
}
Also used : Component(org.eclipse.sw360.datahandler.thrift.components.Component) ExecutionException(java.util.concurrent.ExecutionException) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 69 with Component

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

the class PortletUtils method updateAttachmentsFromRequest.

/**
 * Returns a set of updated attachments from the given request.
 *
 * This function will also take a set of existing attachments that will be
 * updated according to the request. A new set with the updated attachments will
 * be returned.
 *
 * If some of the attachments in the given set are not present in the request,
 * they will not be part of the returned set.
 *
 * Note: the given set will not be changed. However, the containing attachments
 * are changed during update.
 *
 * @param request
 *            request to parse for attachments
 * @param documentAttachments
 *            existing attachments
 *
 * @return set of updated attachments present in the request
 */
public static Set<Attachment> updateAttachmentsFromRequest(PortletRequest request, Set<Attachment> documentAttachments) {
    Set<Attachment> attachments = Sets.newHashSet();
    User user = UserCacheHolder.getUserFromRequest(request);
    String[] ids = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.ATTACHMENT_CONTENT_ID.toString());
    String[] fileNames = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.FILENAME.toString());
    String[] types = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.ATTACHMENT_TYPE.toString());
    String[] createdComments = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.CREATED_COMMENT.toString());
    String[] checkStatuses = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.CHECK_STATUS.toString());
    String[] checkedComments = request.getParameterValues(Release._Fields.ATTACHMENTS.toString() + Attachment._Fields.CHECKED_COMMENT.toString());
    if (ids == null || ids.length == 0) {
        LOGGER.info("No ids transmitted. All attachments will be deleted.");
        return attachments;
    } else if (CommonUtils.oneIsNull(fileNames, types, createdComments, checkStatuses, checkedComments)) {
        LOGGER.error("Invalid request content. One of the attachment parameters is null. No attachments will be saved or deleted.");
        return documentAttachments;
    } else if (!CommonUtils.allHaveSameLength(ids, fileNames, types, createdComments, checkStatuses, checkedComments)) {
        LOGGER.error("Not all of the attachment parameter arrays have the same length! No attachments will be saved or deleted.");
        return documentAttachments;
    }
    Map<String, Attachment> documentAttachmentMap = CommonUtils.nullToEmptySet(documentAttachments).stream().collect(Collectors.toMap(Attachment::getAttachmentContentId, Function.identity()));
    for (int i = 0; i < ids.length; ++i) {
        String id = ids[i];
        Attachment attachment = documentAttachmentMap.get(id);
        if (attachment == null) {
            // the sha1 checksum is not computed here, but in the backend, when updating the
            // component in the database
            attachment = CommonUtils.getNewAttachment(user, id, fileNames[i]);
            documentAttachmentMap.put(attachment.getAttachmentContentId(), attachment);
        }
        // Filename is not overwritten. Unknown reason.
        attachment.setAttachmentType(getAttachmentTypefromString(types[i]));
        attachment.setCreatedComment(createdComments[i]);
        if (getCheckStatusfromString(checkStatuses[i]) != CheckStatus.NOTCHECKED) {
            if (attachment.checkStatus != getCheckStatusfromString(checkStatuses[i]) || !checkedComments[i].equals(attachment.checkedComment)) {
                attachment.setCheckedOn(SW360Utils.getCreatedOn());
                attachment.setCheckedBy(UserCacheHolder.getUserFromRequest(request).getEmail());
                attachment.setCheckedTeam(UserCacheHolder.getUserFromRequest(request).getDepartment());
                attachment.setCheckedComment(checkedComments[i]);
            }
        } else {
            attachment.setCheckedOn(null);
            attachment.setCheckedBy(null);
            attachment.setCheckedTeam(null);
            attachment.setCheckedComment("");
        }
        attachment.setCheckStatus(getCheckStatusfromString(checkStatuses[i]));
        // add attachments to list of added/modified attachments. This way deleted
        // attachments are automatically not in the set
        attachments.add(attachment);
    }
    return attachments;
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment)

Example 70 with Component

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

the class ComponentController method addAttachmentToComponent.

@RequestMapping(value = COMPONENTS_URL + "/{componentId}/attachments", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
public ResponseEntity<HalResource> addAttachmentToComponent(@PathVariable("componentId") String componentId, OAuth2Authentication oAuth2Authentication, @RequestPart("file") MultipartFile file, @RequestPart("attachment") Attachment newAttachment) throws TException {
    final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    Attachment attachment;
    try {
        attachment = attachmentService.uploadAttachment(file, newAttachment, sw360User);
    } catch (IOException e) {
        log.error("failed to upload attachment", e);
        throw new RuntimeException("failed to upload attachment", e);
    }
    final Component component = componentService.getComponentForUserById(componentId, sw360User);
    component.addToAttachments(attachment);
    componentService.updateComponent(component, sw360User);
    final HalResource halRelease = createHalComponent(component, sw360User);
    return new ResponseEntity<>(halRelease, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) IOException(java.io.IOException) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

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