use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseDatabaseHandler method updateWhitelist.
/**
* Update the whitelisted todos for an organisation
*/
public RequestStatus updateWhitelist(String licenseId, Set<String> whitelistTodos, User user) throws SW360Exception {
License license = licenseRepository.get(licenseId);
assertNotNull(license);
String organisation = user.getDepartment();
String businessUnit = SW360Utils.getBUFromOrganisation(organisation);
if (makePermission(license, user).isActionAllowed(RequestedAction.WRITE)) {
List<Todo> todos = todoRepository.get(license.todoDatabaseIds);
for (Todo todo : todos) {
String todoId = todo.getId();
Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
// Add to whitelist if necessary
if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
todo.addToWhitelist(businessUnit);
todoRepository.update(todo);
}
// Remove from whitelist if necessary
if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
currentWhitelist.remove(businessUnit);
todoRepository.update(todo);
}
}
return RequestStatus.SUCCESS;
} else {
// add updated whitelists to todos in moderation request, not yet in database
License licenseForModerationRequest = getLicenseForOrganisationWithOwnModerationRequests(licenseId, user.getDepartment(), user);
List<Todo> todos = licenseForModerationRequest.getTodos();
for (Todo todo : todos) {
String todoId = todo.getId();
Set<String> currentWhitelist = todo.whitelist != null ? todo.whitelist : new HashSet<>();
// Add to whitelist if necessary
if (whitelistTodos.contains(todoId) && !currentWhitelist.contains(businessUnit)) {
todo.addToWhitelist(businessUnit);
}
// Remove from whitelist if necessary
if (!whitelistTodos.contains(todoId) && currentWhitelist.contains(businessUnit)) {
currentWhitelist.remove(businessUnit);
}
}
// Only moderators can edit whitelists!
return moderator.updateLicense(licenseForModerationRequest, user);
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicenseDatabaseHandler method fillLicenseForOrganisation.
private void fillLicenseForOrganisation(String organisation, License license) {
if (license.isSetTodoDatabaseIds()) {
license.setTodos(getTodosByIds(license.todoDatabaseIds));
}
if (license.isSetTodos()) {
for (Todo todo : license.getTodos()) {
// remove other organisations from whitelist of todo
todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
if (todo.isSetObligationDatabaseIds()) {
todo.setObligations(getObligationsByIds(todo.obligationDatabaseIds));
}
}
}
if (license.isSetLicenseTypeDatabaseId()) {
final LicenseType licenseType = licenseTypeRepository.get(license.getLicenseTypeDatabaseId());
license.setLicenseType(licenseType);
}
if (license.isSetRiskDatabaseIds()) {
license.setRisks(getRisksByIds(license.riskDatabaseIds));
license.unsetRiskDatabaseIds();
}
license.setShortname(license.getId());
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class DocxGenerator method fillLicenseList.
private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
XWPFRun licenseHeaderRun = document.createParagraph().createRun();
addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
addNewLines(document, 0);
for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
XWPFParagraph licenseParagraph = document.createParagraph();
licenseParagraph.setStyle(STYLE_HEADING);
String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
addBookmark(licenseParagraph, licenseName, licenseName);
addNewLines(document, 0);
setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
addNewLines(document, 1);
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class DocxGenerator method fillReleaseDetailList.
private void fillReleaseDetailList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, boolean includeObligations) throws TException {
addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true);
setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):");
addNewLines(document, 0);
for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) {
addReleaseTitle(document, parsingResult);
if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) {
addCopyrights(document, parsingResult);
addLicenses(document, parsingResult, includeObligations);
} else {
XWPFRun errorRun = document.createParagraph().createRun();
String errorText = nullToEmptyString(parsingResult.getMessage());
String filename = getFilename(parsingResult);
addFormattedText(errorRun, String.format("Error reading license information: %s", errorText), FONT_SIZE, false, ALERT_COLOR);
addFormattedText(errorRun, String.format("Source file: %s", filename), FONT_SIZE, false, ALERT_COLOR);
}
addNewLines(document, 1);
}
addPageBreak(document);
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class DocxGenerator method addLicenseObligations.
private void addLicenseObligations(XWPFDocument document, String spdxLicense) throws TException {
List<License> sw360Licenses = getLicenses();
XWPFRun todoTitleRun = document.createParagraph().createRun();
addNewLines(todoTitleRun, 0);
Set<String> todos = getTodosFromLicenses(spdxLicense, sw360Licenses);
addFormattedText(todoTitleRun, "Obligations for license " + spdxLicense + ":", FONT_SIZE, true);
for (String todo : todos) {
XWPFParagraph copyPara = document.createParagraph();
copyPara.setSpacingAfter(0);
XWPFRun todoRun = copyPara.createRun();
setText(todoRun, todo);
addNewLines(todoRun, 1);
}
}
Aggregations