Search in sources :

Example 31 with SW360Exception

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

the class ProjectDatabaseHandler method getProjectForEdit.

public Project getProjectForEdit(String id, User user) throws SW360Exception {
    List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
    Project project = getProjectById(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();
            project = moderator.updateProjectFromModerationRequest(project, moderationRequest.getProjectAdditions(), moderationRequest.getProjectDeletions());
            documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
        } else {
            documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
        }
    }
    project.setPermissions(makePermission(project, user).getPermissionMap());
    project.setDocumentState(documentState);
    return project;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ModerationRequest(org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)

Example 32 with SW360Exception

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

the class ProjectDatabaseHandler method updateProjectFromAdditionsAndDeletions.

public RequestStatus updateProjectFromAdditionsAndDeletions(Project projectAdditions, Project projectDeletions, User user) {
    try {
        Project project = getProjectById(projectAdditions.getId(), user);
        project = moderator.updateProjectFromModerationRequest(project, projectAdditions, projectDeletions);
        return updateProject(project, user);
    } catch (SW360Exception e) {
        log.error("Could not get original project when updating from moderation request.");
        return RequestStatus.FAILURE;
    }
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project)

Example 33 with SW360Exception

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

the class ComponentPortlet method updateVulnerabilityVerification.

private void updateVulnerabilityVerification(ResourceRequest request, ResourceResponse response) throws IOException {
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    User user = UserCacheHolder.getUserFromRequest(request);
    VulnerabilityService.Iface vulClient = thriftClients.makeVulnerabilityClient();
    RequestStatus requestStatus = RequestStatus.SUCCESS;
    try {
        if (vulnerabilityIds.length != releaseIds.length) {
            throw new SW360Exception("Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!");
        }
        for (int i = 0; i < vulnerabilityIds.length; i++) {
            String vulnerabilityId = vulnerabilityIds[i];
            String releaseId = releaseIds[i];
            Vulnerability dbVulnerability = vulClient.getVulnerabilityByExternalId(vulnerabilityId, user);
            ReleaseVulnerabilityRelation dbRelation = vulClient.getRelationByIds(releaseId, dbVulnerability.getId(), user);
            ReleaseVulnerabilityRelation resultRelation = ComponentPortletUtils.updateReleaseVulnerabilityRelationFromRequest(dbRelation, request);
            requestStatus = vulClient.updateReleaseVulnerabilityRelation(resultRelation, user);
            if (requestStatus != RequestStatus.SUCCESS) {
                break;
            }
        }
    } catch (TException e) {
        log.error("Error updating vulnerability verification in backend.", e);
        requestStatus = RequestStatus.FAILURE;
    }
    JSONObject responseData = JSONFactoryUtil.createJSONObject();
    responseData.put(PortalConstants.REQUEST_STATUS, requestStatus.toString());
    PrintWriter writer = response.getWriter();
    writer.write(responseData.toString());
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService) Vulnerability(org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability) JSONObject(com.liferay.portal.kernel.json.JSONObject) ReleaseVulnerabilityRelation(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ReleaseVulnerabilityRelation) PrintWriter(java.io.PrintWriter)

Example 34 with SW360Exception

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

the class ProjectPortletUtils method updateProjectVulnerabilityRatingFromRequest.

public static ProjectVulnerabilityRating updateProjectVulnerabilityRatingFromRequest(Optional<ProjectVulnerabilityRating> projectVulnerabilityRatings, ResourceRequest request) throws SW360Exception {
    String projectId = request.getParameter(PortalConstants.PROJECT_ID);
    ProjectVulnerabilityRating projectVulnerabilityRating = projectVulnerabilityRatings.orElse(new ProjectVulnerabilityRating().setProjectId(projectId).setVulnerabilityIdToReleaseIdToStatus(new HashMap<>()));
    if (!projectVulnerabilityRating.isSetVulnerabilityIdToReleaseIdToStatus()) {
        projectVulnerabilityRating.setVulnerabilityIdToReleaseIdToStatus(new HashMap<>());
    }
    Map<String, Map<String, List<VulnerabilityCheckStatus>>> vulnerabilityIdToReleaseIdToStatus = projectVulnerabilityRating.getVulnerabilityIdToReleaseIdToStatus();
    String[] vulnerabilityIds = request.getParameterValues(PortalConstants.VULNERABILITY_IDS + "[]");
    String[] releaseIds = request.getParameterValues(PortalConstants.RELEASE_IDS + "[]");
    if (vulnerabilityIds.length != releaseIds.length) {
        String message = "Length of vulnerabilities (" + vulnerabilityIds.length + ") does not match the length of releases (" + releaseIds.length + ")!";
        log.error(message);
        throw new SW360Exception(message);
    }
    for (int i = 0; i < vulnerabilityIds.length; i++) {
        String vulnerabilityId = vulnerabilityIds[i];
        String releaseId = releaseIds[i];
        Map<String, List<VulnerabilityCheckStatus>> releaseIdToStatus = vulnerabilityIdToReleaseIdToStatus.computeIfAbsent(vulnerabilityId, k -> new HashMap<>());
        List<VulnerabilityCheckStatus> vulnerabilityCheckStatusHistory = releaseIdToStatus.computeIfAbsent(releaseId, k -> new ArrayList<>());
        VulnerabilityCheckStatus vulnerabilityCheckStatus = newVulnerabilityCheckStatusFromRequest(request);
        vulnerabilityCheckStatusHistory.add(vulnerabilityCheckStatus);
    }
    return projectVulnerabilityRating;
}
Also used : ProjectVulnerabilityRating(org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating) ImmutableMap(com.google.common.collect.ImmutableMap) VulnerabilityCheckStatus(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus)

Example 35 with SW360Exception

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

the class ComponentUploadPortlet method updateLicenses.

@UsedAsLiferayAction
public void updateLicenses(ActionRequest request, ActionResponse response) throws PortletException, IOException, TException {
    final HashMap<String, InputStream> inputMap = new HashMap<>();
    User user = UserCacheHolder.getUserFromRequest(request);
    try {
        fillFilenameInputStreamMap(request, inputMap);
        if (ZipTools.isValidLicenseArchive(inputMap)) {
            final LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
            log.debug("Parsing risk categories ...");
            Map<Integer, RiskCategory> riskCategoryMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(RISK_CATEGORY_FILE), RiskCategory.class, Integer.class, user);
            log.debug("Parsing risks ...");
            Map<Integer, Risk> riskMap = getIntegerRiskMap(licenseClient, riskCategoryMap, inputMap.get(RISK_FILE), user);
            log.debug("Parsing obligations ...");
            Map<Integer, Obligation> obligationMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(OBLIGATION_FILE), Obligation.class, Integer.class, user);
            log.debug("Parsing obligation todos ...");
            List<CSVRecord> obligationTodoRecords = readAsCSVRecords(inputMap.get(OBLIGATION_TODO_FILE));
            Map<Integer, Set<Integer>> obligationTodoMapping = convertRelationalTableWithIntegerKeys(obligationTodoRecords);
            log.debug("Parsing license types ...");
            Map<Integer, LicenseType> licenseTypeMap = getIdentifierToTypeMapAndWriteMissingToDatabase(licenseClient, inputMap.get(LICENSETYPE_FILE), LicenseType.class, Integer.class, user);
            log.debug("Parsing todos ...");
            Map<Integer, Todo> todoMap = getTodoMapAndWriteMissingToDatabase(licenseClient, obligationMap, obligationTodoMapping, inputMap.get(TODO_FILE), user);
            if (inputMap.containsKey(CUSTOM_PROPERTIES_FILE)) {
                log.debug("Parsing custom properties ...");
                Map<Integer, PropertyWithValue> customPropertiesMap = getCustomPropertiesWithValuesByIdAndWriteMissingToDatabase(licenseClient, inputMap.get(CUSTOM_PROPERTIES_FILE), user);
                log.debug("Parsing todo custom properties relation ...");
                List<CSVRecord> todoPropertiesRecord = readAsCSVRecords(inputMap.get(TODO_CUSTOM_PROPERTIES_FILE));
                Map<Integer, Set<Integer>> todoPropertiesMap = convertRelationalTableWithIntegerKeys(todoPropertiesRecord);
                todoMap = updateTodoMapWithCustomPropertiesAndWriteToDatabase(licenseClient, todoMap, customPropertiesMap, todoPropertiesMap, user);
            }
            log.debug("Parsing license todos ...");
            List<CSVRecord> licenseTodoRecord = readAsCSVRecords(inputMap.get(LICENSE_TODO_FILE));
            Map<String, Set<Integer>> licenseTodoMap = convertRelationalTable(licenseTodoRecord);
            log.debug("Parsing license risks ...");
            List<CSVRecord> licenseRiskRecord = readAsCSVRecords(inputMap.get(LICENSE_RISK_FILE));
            Map<String, Set<Integer>> licenseRiskMap = convertRelationalTable(licenseRiskRecord);
            log.debug("Parsing licenses ...");
            List<CSVRecord> licenseRecord = readAsCSVRecords(inputMap.get(LICENSE_FILE));
            final List<License> licensesToAdd = ConvertRecord.fillLicenses(licenseRecord, licenseTypeMap, todoMap, riskMap, licenseTodoMap, licenseRiskMap);
            addLicenses(licenseClient, licensesToAdd, log, user);
        } else {
            throw new SW360Exception("Invalid file format");
        }
    } finally {
        for (InputStream inputStream : inputMap.values()) {
            inputStream.close();
        }
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) CSVRecord(org.apache.commons.csv.CSVRecord) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Aggregations

SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)23 IOException (java.io.IOException)10 InputStream (java.io.InputStream)9 TException (org.apache.thrift.TException)9 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)9 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)9 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)8 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 Test (org.junit.Test)4 CommonUtils.isTemporaryTodo (org.eclipse.sw360.datahandler.common.CommonUtils.isTemporaryTodo)3 SW360Utils.fieldValueAsString (org.eclipse.sw360.datahandler.common.SW360Utils.fieldValueAsString)3 Component (org.eclipse.sw360.datahandler.thrift.components.Component)3 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 PipedInputStream (java.io.PipedInputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 ConcatClosingInputStream (org.eclipse.sw360.datahandler.common.ConcatClosingInputStream)2 WrappedSW360Exception (org.eclipse.sw360.datahandler.common.WrappedException.WrappedSW360Exception)2