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;
}
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;
}
}
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());
}
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;
}
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();
}
}
}
Aggregations