Search in sources :

Example 1 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class ProjectController method downloadLicenseInfo.

@RequestMapping(value = PROJECTS_URL + "/{id}/licenseinfo", method = RequestMethod.GET)
public void downloadLicenseInfo(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication, @RequestParam("generatorClassName") String generatorClassName, HttpServletResponse response) throws TException, IOException {
    final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    final Project sw360Project = projectService.getProjectForUserById(id, sw360User);
    final Map<String, Set<String>> selectedReleaseAndAttachmentIds = new HashMap<>();
    for (final String releaseId : sw360Project.getReleaseIdToUsage().keySet()) {
        final Release release = releaseService.getReleaseForUserById(releaseId, sw360User);
        if (release.isSetAttachments()) {
            if (!selectedReleaseAndAttachmentIds.containsKey(releaseId)) {
                selectedReleaseAndAttachmentIds.put(releaseId, new HashSet<>());
            }
            final Set<Attachment> attachments = release.getAttachments();
            for (final Attachment attachment : attachments) {
                selectedReleaseAndAttachmentIds.get(releaseId).add(attachment.getAttachmentContentId());
            }
        }
    }
    // TODO: implement method to determine excluded licenses
    final Map<String, Set<LicenseNameWithText>> excludedLicenses = new HashMap<>();
    final String projectName = sw360Project.getName();
    final String timestamp = SW360Utils.getCreatedOn();
    final OutputFormatInfo outputFormatInfo = licenseInfoService.getOutputFormatInfoForGeneratorClass(generatorClassName);
    final String filename = String.format("LicenseInfo-%s-%s.%s", projectName, timestamp, outputFormatInfo.getFileExtension());
    final LicenseInfoFile licenseInfoFile = licenseInfoService.getLicenseInfoFile(sw360Project, sw360User, generatorClassName, selectedReleaseAndAttachmentIds, excludedLicenses);
    byte[] byteContent = licenseInfoFile.bufferForGeneratedOutput().array();
    response.setContentType(outputFormatInfo.getMimeType());
    response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
    FileCopyUtils.copy(byteContent, response.getOutputStream());
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) LicenseInfoFile(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) OutputFormatInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo) Project(org.eclipse.sw360.datahandler.thrift.projects.Project) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 2 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class Sw360AttachmentService method uploadAttachment.

public Attachment uploadAttachment(MultipartFile file, Attachment newAttachment, User sw360User) throws IOException, TException {
    // TODO: shouldn't the fileName be taken from newAttachment?
    String fileName = file.getOriginalFilename();
    String contentType = file.getContentType();
    final AttachmentContent attachmentContent = makeAttachmentContent(fileName, contentType);
    final AttachmentConnector attachmentConnector = getConnector();
    Attachment attachment = new AttachmentFrontendUtils().uploadAttachmentContent(attachmentContent, file.getInputStream(), sw360User);
    attachment.setSha1(attachmentConnector.getSha1FromAttachmentContentId(attachmentContent.getId()));
    AttachmentType attachmentType = newAttachment.getAttachmentType();
    if (attachmentType != null) {
        attachment.setAttachmentType(attachmentType);
    }
    CheckStatus checkStatus = newAttachment.getCheckStatus();
    if (checkStatus != null) {
        attachment.setCheckStatus(checkStatus);
    }
    return attachment;
}
Also used : AttachmentFrontendUtils(org.eclipse.sw360.commonIO.AttachmentFrontendUtils) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector)

Example 3 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class CompareTodos method renderTodoRow.

private static void renderTodoRow(StringBuilder display, Todo todo) {
    display.append("<tr>");
    for (Todo._Fields field : RELEVANT_FIELDS) {
        FieldMetaData fieldMetaData = Todo.metaDataMap.get(field);
        Object fieldValue = todo.getFieldValue(field);
        if (field.equals(Todo._Fields.OBLIGATIONS) && fieldValue != null) {
            fieldValue = ((List<Obligation>) fieldValue).stream().map(Obligation::getName).collect(Collectors.toList());
        }
        display.append(String.format("<td>%s</td>", getDisplayString(fieldMetaData.valueMetaData.type, fieldValue)));
    }
    display.append("</tr>");
}
Also used : Todo(org.eclipse.sw360.datahandler.thrift.licenses.Todo) FieldMetaData(org.apache.thrift.meta_data.FieldMetaData) Obligation(org.eclipse.sw360.datahandler.thrift.licenses.Obligation)

Example 4 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicensesPortlet method prepareDetailView.

private void prepareDetailView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
    String id = request.getParameter(LICENSE_ID);
    User user = UserCacheHolder.getUserFromRequest(request);
    request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
    if (id != null) {
        try {
            LicenseService.Iface client = thriftClients.makeLicenseClient();
            License moderationLicense = client.getByIDWithOwnModerationRequests(id, user.getDepartment(), user);
            List<Todo> allTodos = nullToEmptyList(moderationLicense.getTodos());
            List<Todo> addedTodos = allTodos.stream().filter(CommonUtils::isTemporaryTodo).collect(Collectors.toList());
            List<Todo> currentTodos = allTodos.stream().filter(t -> !CommonUtils.isTemporaryTodo(t)).collect(Collectors.toList());
            request.setAttribute(ADDED_TODOS_FROM_MODERATION_REQUEST, addedTodos);
            request.setAttribute(DB_TODOS_FROM_MODERATION_REQUEST, currentTodos);
            request.setAttribute(MODERATION_LICENSE_DETAIL, moderationLicense);
            License dbLicense = client.getByID(id, user.getDepartment());
            request.setAttribute(KEY_LICENSE_DETAIL, dbLicense);
            List<Obligation> obligations = client.getObligations();
            request.setAttribute(KEY_OBLIGATION_LIST, obligations);
            addLicenseBreadcrumb(request, response, moderationLicense);
        } catch (TException e) {
            log.error("Error fetching license details from backend", e);
            setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
        }
    }
}
Also used : java.util(java.util) User(org.eclipse.sw360.datahandler.thrift.users.User) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) TMP_TODO_ID_PREFIX(org.eclipse.sw360.datahandler.common.CommonUtils.TMP_TODO_ID_PREFIX) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Function(java.util.function.Function) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Strings(com.google.common.base.Strings) Logger(org.apache.log4j.Logger) SessionMessages(com.liferay.portal.kernel.servlet.SessionMessages) CONTENT_TYPE_OPENXML_SPREADSHEET(org.eclipse.sw360.datahandler.common.SW360Constants.CONTENT_TYPE_OPENXML_SPREADSHEET) ThriftEnumUtils(org.eclipse.sw360.datahandler.common.ThriftEnumUtils) Ternary(org.eclipse.sw360.datahandler.thrift.Ternary) javax.portlet(javax.portlet) org.eclipse.sw360.datahandler.thrift.licenses(org.eclipse.sw360.datahandler.thrift.licenses) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) ImmutableSet(com.google.common.collect.ImmutableSet) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) HttpServletResponse(javax.servlet.http.HttpServletResponse) TException(org.apache.thrift.TException) PermissionUtils(org.eclipse.sw360.datahandler.permissions.PermissionUtils) IOException(java.io.IOException) CommonUtils.nullToEmptyList(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyList) Collectors(java.util.stream.Collectors) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) ErrorMessages(org.eclipse.sw360.portal.common.ErrorMessages) EnumUtils(org.apache.commons.lang.enums.EnumUtils) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) LicenseExporter(org.eclipse.sw360.exporter.LicenseExporter) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User)

Example 5 with Todo

use of org.eclipse.sw360.datahandler.thrift.licenses.Todo in project sw360portal by sw360.

the class LicenseModerationRequestGenerator method setAdditionsAndDeletions.

@Override
public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, License updateLicense, License actualLicense) {
    updateDocument = updateLicense;
    actualDocument = actualLicense;
    documentAdditions = new License();
    documentDeletions = new License();
    // required fields:
    documentAdditions.setFullname(updateLicense.getFullname());
    documentAdditions.setId(actualLicense.getId());
    documentDeletions.setFullname(actualLicense.getFullname());
    documentDeletions.setId(actualLicense.getId());
    Map<String, Todo> actualTodos = Maps.uniqueIndex(nullToEmptyList(actualLicense.getTodos()), Todo::getId);
    for (Todo updateTodo : updateLicense.getTodos()) {
        if (!actualTodos.containsKey(updateTodo.getId())) {
            if (!documentAdditions.isSetTodos()) {
                documentAdditions.setTodos(new ArrayList<>());
            }
            documentAdditions.getTodos().add(updateTodo);
        } else {
            Todo actualTodo = actualTodos.get(updateTodo.getId());
            Set<String> actualWhitelist = actualTodo.whitelist != null ? actualTodo.whitelist : new HashSet<String>();
            Set<String> updateWhitelist = updateTodo.whitelist != null ? updateTodo.whitelist : new HashSet<String>();
            String departement = request.getRequestingUserDepartment();
            if (updateWhitelist.contains(departement) && !actualWhitelist.contains(departement)) {
                if (!documentAdditions.isSetTodos()) {
                    documentAdditions.setTodos(new ArrayList<>());
                }
                documentAdditions.getTodos().add(updateTodo);
            } else if (!updateWhitelist.contains(departement) && actualWhitelist.contains(departement)) {
                if (!documentDeletions.isSetTodos()) {
                    documentDeletions.setTodos(new ArrayList<>());
                }
                documentDeletions.getTodos().add(actualTodo);
            }
        }
    }
    request.setLicenseAdditions(documentAdditions);
    request.setLicenseDeletions(documentDeletions);
    return request;
}
Also used : Todo(org.eclipse.sw360.datahandler.thrift.licenses.Todo) License(org.eclipse.sw360.datahandler.thrift.licenses.License)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)7 TException (org.apache.thrift.TException)6 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)6 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 Strings (com.google.common.base.Strings)3 java.util (java.util)3 CSVRecord (org.apache.commons.csv.CSVRecord)3 Logger (org.apache.log4j.Logger)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 ThriftEnumUtils (org.eclipse.sw360.datahandler.common.ThriftEnumUtils)3 Ternary (org.eclipse.sw360.datahandler.thrift.Ternary)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 org.eclipse.sw360.datahandler.thrift.licenses (org.eclipse.sw360.datahandler.thrift.licenses)3 Todo (org.eclipse.sw360.datahandler.thrift.licenses.Todo)3 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)3 NotNull (org.jetbrains.annotations.NotNull)3 Function (com.google.common.base.Function)2 com.google.common.collect (com.google.common.collect)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2