use of org.eclipse.sw360.datahandler.thrift.users.User 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.users.User in project sw360portal by sw360.
the class LicensesPortlet method prepareStandardView.
private void prepareStandardView(RenderRequest request) {
log.debug("Enter license table view");
List<License> licenses;
User user = UserCacheHolder.getUserFromRequest(request);
request.setAttribute(IS_USER_AT_LEAST_CLEARING_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user) ? "Yes" : "No");
try {
LicenseService.Iface client = thriftClients.makeLicenseClient();
licenses = client.getLicenseSummary();
} catch (TException e) {
log.error("Could not fetch license summary from backend!", e);
licenses = new ArrayList<>();
}
request.setAttribute(LICENSE_LIST, licenses);
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class LicensesPortlet method prepareEditView.
private void prepareEditView(RenderRequest request, RenderResponse response) {
String id = request.getParameter(LICENSE_ID);
User user = UserCacheHolder.getUserFromRequest(request);
LicenseService.Iface client = thriftClients.makeLicenseClient();
try {
licenseTypes = client.getLicenseTypes();
request.setAttribute(LICENSE_TYPE_CHOICE, licenseTypes);
} catch (TException e) {
log.error("Error fetching license types from backend", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
}
if (id != null) {
try {
License license = client.getByID(id, user.getDepartment());
request.setAttribute(KEY_LICENSE_DETAIL, license);
addLicenseBreadcrumb(request, response, license);
} catch (TException e) {
log.error("Error fetching license details from backend", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_LICENSE);
}
} else {
if (request.getAttribute(KEY_LICENSE_DETAIL) == null) {
SessionMessages.add(request, "request_processed", "New License");
License license = new License();
request.setAttribute(KEY_LICENSE_DETAIL, license);
}
}
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class LicensesPortlet method update.
@UsedAsLiferayAction
public void update(ActionRequest request, ActionResponse response) throws PortletException, IOException {
LicenseService.Iface client = thriftClients.makeLicenseClient();
String licenseId = request.getParameter(LICENSE_ID);
User user = UserCacheHolder.getUserFromRequest(request);
License license = prepareLicenseForUpdate(request, client, licenseId, user);
boolean isNewLicense = isNullOrEmpty(licenseId);
boolean isAttemptToOverwriteExistingByNew = isAttemptToOverwriteExistingByNew(license, user, isNewLicense, client);
RequestStatus requestStatus = updateLicense(license, user, isAttemptToOverwriteExistingByNew, client);
if (isAttemptToOverwriteExistingByNew) {
response.setRenderParameter(PAGENAME, PAGENAME_EDIT);
setSW360SessionError(request, ErrorMessages.LICENSE_SHORTNAME_TAKEN);
request.setAttribute(KEY_LICENSE_DETAIL, license);
} else if (isNewLicense) {
response.setRenderParameter(PAGENAME, PAGENAME_VIEW);
setSessionMessage(request, requestStatus, "License", "adde");
} else {
response.setRenderParameter(LICENSE_ID, licenseId);
response.setRenderParameter(PAGENAME, PAGENAME_DETAIL);
response.setRenderParameter(SELECTED_TAB, "Details");
setSessionMessage(request, requestStatus, "License", "update");
}
}
use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.
the class AttachmentAwarePortlet method doGetAttachmentForDisplay.
private void doGetAttachmentForDisplay(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
final String attachmentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
final User user = UserCacheHolder.getUserFromRequest(request);
Attachment attachment = attachmentPortletUtils.getAttachmentForDisplay(user, attachmentId);
if (attachment == null) {
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
} else {
writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(attachment));
}
}
Aggregations