use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ModerationPortlet method renderEditViewForId.
private void renderEditViewForId(RenderRequest request, RenderResponse response, String id) throws IOException, PortletException, TException {
if (id != null) {
ModerationRequest moderationRequest = null;
User user = UserCacheHolder.getUserFromRequest(request);
try {
ModerationService.Iface client = thriftClients.makeModerationClient();
moderationRequest = client.getModerationRequestById(id);
boolean actionsAllowed = moderationRequest.getModerators().contains(user.getEmail()) && ModerationPortletUtils.isOpenModerationRequest(moderationRequest);
request.setAttribute(PortalConstants.MODERATION_ACTIONS_ALLOWED, actionsAllowed);
if (actionsAllowed) {
SessionMessages.add(request, "request_processed", "You have assigned yourself to this moderation request.");
client.setInProgress(id, user);
}
request.setAttribute(PortalConstants.MODERATION_REQUEST, moderationRequest);
addModerationBreadcrumb(request, response, moderationRequest);
} catch (TException e) {
log.error("Error fetching moderation details from backend", e);
}
if (moderationRequest != null) {
switch(moderationRequest.getDocumentType()) {
case COMPONENT:
renderComponentModeration(request, response, moderationRequest, user);
break;
case RELEASE:
VendorService.Iface vendorClient = thriftClients.makeVendorClient();
Release additions = moderationRequest.getReleaseAdditions();
if (additions.isSetVendorId()) {
additions.setVendor(vendorClient.getByID(additions.getVendorId()));
}
Release deletions = moderationRequest.getReleaseDeletions();
if (deletions.isSetVendorId()) {
deletions.setVendor(vendorClient.getByID(deletions.getVendorId()));
}
renderReleaseModeration(request, response, moderationRequest, user);
break;
case PROJECT:
renderProjectModeration(request, response, moderationRequest, user);
break;
case LICENSE:
renderLicenseModeration(request, response, moderationRequest, user);
break;
case USER:
renderUserModeration(request, response, moderationRequest, user);
break;
}
}
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class ProjectPortletUtils method getExcludedLicensesPerAttachmentIdFromRequest.
/**
* Returns a map of excluded licenses. They key is an attachment content id, the
* value is a list of excluded licenses.
* <p>
* For this method to work it is crucial that there is a so called
* "license-store-<attachmentContentId>" map in the session. This map must
* contain a mapping from a key to a {@link LicenseNameWithText} object.
*
* @param attachmentContentIds list of attachment content id to check for exclusions in the
* request
* @param request the request containing the excluded licenses as parameters
* @return a map containing the licenses to exclude
* @see ProjectPortletUtilsTest for a better understanding
*/
public static Map<String, Set<LicenseNameWithText>> getExcludedLicensesPerAttachmentIdFromRequest(Set<String> attachmentContentIds, ResourceRequest request) {
Map<String, Set<LicenseNameWithText>> excludedLicenses = Maps.newHashMap();
for (String attachmentContentId : attachmentContentIds) {
String[] checkboxes = request.getParameterValues(attachmentContentId);
String[] keys = request.getParameterValues(attachmentContentId + "_key");
if (checkboxes == null) {
// no details present
continue;
}
@SuppressWarnings("unchecked") Map<String, LicenseNameWithText> licenseStore = (Map<String, LicenseNameWithText>) request.getPortletSession().getAttribute(ProjectPortlet.LICENSE_STORE_KEY_PREFIX + attachmentContentId);
if (licenseStore == null) {
throw new IllegalStateException("No license store found for attachment content id " + attachmentContentId);
}
Set<Integer> includedIds = Arrays.stream(checkboxes).map(s -> Integer.valueOf(s)).collect(Collectors.toSet());
Set<LicenseNameWithText> licenseNameWithTexts = Sets.newHashSet();
for (int index = 0; index < keys.length; index++) {
if (includedIds.contains(index)) {
// transferred
continue;
}
LicenseNameWithText licenseNameWithText = licenseStore.get(keys[index]);
if (licenseNameWithText == null) {
throw new IllegalStateException("No license found for key " + keys[index]);
}
licenseNameWithTexts.add(licenseNameWithText);
}
excludedLicenses.put(attachmentContentId, licenseNameWithTexts);
}
return excludedLicenses;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class DisplayProjectChanges method prepareLicenseInfoHeaderTextInProject.
private Project prepareLicenseInfoHeaderTextInProject(Project project) {
Project modifiedProject = project.deepCopy();
String defaultTextAsHtmlForDisplay = "<span title=\"" + defaultLicenseInfoHeaderText + "\">" + PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT_FOR_DISPALY + "</span>";
if (!modifiedProject.isSetLicenseInfoHeaderText()) {
// if the project contains the default license info header text, we wrap it into an html span-element such that the default text is given as a hover text.
// this is only done for displaying it in a three-way merge in a moderation request.
modifiedProject.setLicenseInfoHeaderText(defaultTextAsHtmlForDisplay);
} else {
// for a custom text escape html properly
modifiedProject.setLicenseInfoHeaderText(StringEscapeUtils.escapeHtml(modifiedProject.getLicenseInfoHeaderText()).replace("\n", "<br>"));
}
return modifiedProject;
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License 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);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.licenses.License in project sw360portal by sw360.
the class LicensesPortlet method delete.
@UsedAsLiferayAction
public void delete(ActionRequest request, ActionResponse response) throws PortletException, IOException {
RequestStatus requestStatus = deleteLicense(request);
setSessionMessage(request, requestStatus, "License", "remove");
}
Aggregations