use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ModerationPortlet method renderLicenseModeration.
public void renderLicenseModeration(RenderRequest request, RenderResponse response, ModerationRequest moderationRequest, User user) throws IOException, PortletException, TException {
License actual_license = null;
User requestingUser = UserCacheHolder.getUserFromEmail(moderationRequest.getRequestingUser());
try {
LicenseService.Iface client = thriftClients.makeLicenseClient();
actual_license = client.getByID(moderationRequest.getDocumentId(), requestingUser.getDepartment());
request.setAttribute(KEY_LICENSE_DETAIL, actual_license);
List<Obligation> obligations = client.getObligations();
request.setAttribute(KEY_OBLIGATION_LIST, obligations);
} catch (TException e) {
log.error("Could not retrieve license", e);
}
if (actual_license == null) {
renderNextModeration(request, response, user, "Ignored unretrievable target", thriftClients.makeModerationClient(), moderationRequest);
return;
}
include("/html/moderation/licenses/merge.jsp", request, response);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ProjectPortlet method serveAttachmentFileLicenses.
private void serveAttachmentFileLicenses(ResourceRequest request, ResourceResponse response) throws IOException {
final User user = UserCacheHolder.getUserFromRequest(request);
final String attachmentContentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
final LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
try {
Release release = componentClient.getReleaseById(request.getParameter(PortalConstants.RELEASE_ID), user);
List<LicenseInfoParsingResult> licenseInfos = licenseInfoClient.getLicenseInfoForAttachment(release, attachmentContentId, user);
// We generate a JSON-serializable list of licenses here.
// In addition we remember the license information for exclusion later on
Map<String, LicenseNameWithText> licenseStore = Maps.newHashMap();
List<Map<String, String>> licenses = Lists.newArrayList();
licenseInfos.forEach(licenseInfoResult -> addLicenseInfoResultToJsonSerializableLicensesList(licenseInfoResult, licenses, licenseStore::put));
licenses.sort((l1, l2) -> Strings.nullToEmpty(l1.get(LICENSE_NAME_WITH_TEXT_NAME)).compareTo(l2.get(LICENSE_NAME_WITH_TEXT_NAME)));
request.getPortletSession().setAttribute(LICENSE_STORE_KEY_PREFIX + attachmentContentId, licenseStore);
writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(licenses));
} catch (TException exception) {
log.error("Cannot retrieve license information for attachment id " + attachmentContentId + ".", exception);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class DatabaseSanitation method deleteAllLicenseInformation.
private void deleteAllLicenseInformation(ResourceRequest request, ResourceResponse response) {
User user = UserCacheHolder.getUserFromRequest(request);
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
try {
RequestSummary requestSummary = licenseClient.deleteAllLicenseInformation(user);
renderRequestSummary(request, response, requestSummary);
} catch (TException te) {
log.error("Got TException when trying to delete all license information.", te);
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License 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();
}
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class SPDXParserTools method getAllLicenseTextsFromInfo.
private static Stream<LicenseNameWithText> getAllLicenseTextsFromInfo(AnyLicenseInfo spdxLicenseInfo) {
log.trace("Seen the spdxLicenseInfo=" + spdxLicenseInfo.toString() + "]");
if (spdxLicenseInfo instanceof LicenseSet) {
LicenseSet LicenseSet = (LicenseSet) spdxLicenseInfo;
return Arrays.stream(LicenseSet.getMembers()).flatMap(SPDXParserTools::getAllLicenseTextsFromInfo);
} else if (spdxLicenseInfo instanceof ExtractedLicenseInfo) {
ExtractedLicenseInfo extractedLicenseInfo = (ExtractedLicenseInfo) spdxLicenseInfo;
return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(extractedLicenseInfo)).setLicenseText(extractedLicenseInfo.getExtractedText()));
} else if (spdxLicenseInfo instanceof License) {
License license = (License) spdxLicenseInfo;
return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(license)).setLicenseText(license.getLicenseText()));
} else if (spdxLicenseInfo instanceof OrLaterOperator) {
OrLaterOperator orLaterOperator = (OrLaterOperator) spdxLicenseInfo;
return getAllLicenseTextsFromInfo(orLaterOperator.getLicense()).map(lnwt -> lnwt.setLicenseName(lnwt.getLicenseName() + " or later"));
} else if (spdxLicenseInfo instanceof WithExceptionOperator) {
WithExceptionOperator withExceptionOperator = (WithExceptionOperator) spdxLicenseInfo;
String licenseExceptionText = withExceptionOperator.getException().getLicenseExceptionText();
return getAllLicenseTextsFromInfo(withExceptionOperator.getLicense()).map(licenseNWT -> licenseNWT.setLicenseText(licenseNWT.getLicenseText() + "\n\n" + licenseExceptionText).setLicenseName(licenseNWT.getLicenseName() + " with " + withExceptionOperator.getException().getName()));
}
log.debug("the spdxLicenseInfo=[" + spdxLicenseInfo.toString() + "] did not contain any license information");
return Stream.empty();
}
Aggregations