use of org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest in project sw360 by eclipse.
the class ProjectPortlet method createClearingRequest.
private void createClearingRequest(ResourceRequest request, ResourceResponse response) throws PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
ClearingRequest clearingRequest = null;
AddDocumentRequestSummary requestSummary = null;
try {
JsonNode crNode = OBJECT_MAPPER.readValue(request.getParameter(CLEARING_REQUEST), JsonNode.class);
clearingRequest = OBJECT_MAPPER.convertValue(crNode, ClearingRequest.class);
clearingRequest.setRequestingUser(user.getEmail());
clearingRequest.setClearingState(ClearingRequestState.NEW);
ModerationService.Iface modClient = thriftClients.makeModerationClient();
Integer criticalCount = modClient.getCriticalClearingRequestCount();
clearingRequest.setPriority(criticalCount > 1 ? null : clearingRequest.getPriority());
LiferayPortletURL projectUrl = createDetailLinkTemplate(request);
projectUrl.setParameter(PROJECT_ID, clearingRequest.getProjectId());
projectUrl.setParameter(PAGENAME, PAGENAME_DETAIL);
ProjectService.Iface client = thriftClients.makeProjectClient();
Integer dateLimit = ModerationPortletUtils.loadPreferredClearingDateLimit(request, user);
dateLimit = (ClearingRequestPriority.CRITICAL.equals(clearingRequest.getPriority()) && criticalCount < 2) ? 0 : (dateLimit < 1) ? 7 : dateLimit;
if (!SW360Utils.isValidDate(clearingRequest.getRequestedClearingDate(), DateTimeFormatter.ISO_LOCAL_DATE, Long.valueOf(dateLimit))) {
log.warn("Invalid requested clearing date: " + clearingRequest.getRequestedClearingDate() + " is entered, by user: " + user.getEmail());
requestSummary = new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.FAILURE).setMessage("Invalid requested clearing date");
} else {
requestSummary = client.createClearingRequest(clearingRequest, user, projectUrl.toString());
}
} catch (IOException | TException e) {
log.error("Error creating clearing request for project: " + clearingRequest.getProjectId(), e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
}
try {
JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(response.getWriter());
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(RESULT, requestSummary.getRequestStatus().toString());
if (!AddDocumentRequestStatus.SUCCESS.equals(requestSummary.getRequestStatus())) {
ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", request.getLocale(), getClass());
jsonGenerator.writeStringField(SW360Constants.MESSAGE, LanguageUtil.get(resourceBundle, requestSummary.getMessage().replace(' ', '.').toLowerCase()));
} else {
jsonGenerator.writeStringField(CLEARING_REQUEST_ID, requestSummary.getId());
}
jsonGenerator.writeEndObject();
jsonGenerator.close();
} catch (IOException e) {
log.error("Cannot write JSON response for clearing request id " + requestSummary.getId() + " in project " + clearingRequest.getProjectId() + ".", e);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
}
}
use of org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest in project sw360 by eclipse.
the class ModerationPortlet method renderStandardView.
public void renderStandardView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
User user = UserCacheHolder.getUserFromRequest(request);
HttpServletRequest httpServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
String selectedTab = httpServletRequest.getParameter(SELECTED_TAB);
List<ClearingRequest> openClearingRequests = null;
List<ClearingRequest> closedClearingRequests = null;
ModerationService.Iface client = thriftClients.makeModerationClient();
try {
Set<ClearingRequest> clearingRequestsSet = client.getMyClearingRequests(user);
clearingRequestsSet.addAll(client.getClearingRequestsByBU(user.getDepartment()));
if (!CommonUtils.isNullOrEmptyMap(user.getSecondaryDepartmentsAndRoles())) {
user.getSecondaryDepartmentsAndRoles().keySet().stream().forEach(department -> wrapTException(() -> {
clearingRequestsSet.addAll(client.getClearingRequestsByBU(department));
}));
}
Map<Boolean, List<ClearingRequest>> partitionedClearingRequests = clearingRequestsSet.stream().collect(Collectors.groupingBy(ModerationPortletUtils::isClosedClearingRequest));
closedClearingRequests = partitionedClearingRequests.get(true);
openClearingRequests = partitionedClearingRequests.get(false);
} catch (TException e) {
log.error("Could not fetch clearing requests from backend!", e);
}
request.setAttribute(CLEARING_REQUESTS, CommonUtils.nullToEmptyList(openClearingRequests));
request.setAttribute(CLOSED_CLEARING_REQUESTS, CommonUtils.nullToEmptyList(closedClearingRequests));
request.setAttribute(IS_CLEARING_EXPERT, PermissionUtils.isUserAtLeast(UserGroup.CLEARING_EXPERT, user));
PortletUtils.getBaBlSelection(request, user);
List<Organization> organizations = UserUtils.getOrganizations(request);
request.setAttribute(PortalConstants.ORGANIZATIONS, organizations);
if (CommonUtils.isNotNullEmptyOrWhitespace(selectedTab)) {
request.setAttribute(SELECTED_TAB, selectedTab);
}
for (ModerationRequest._Fields moderationFilteredField : MODERATION_FILTERED_FIELDS) {
request.setAttribute(moderationFilteredField.getFieldName(), nullToEmpty(request.getParameter(moderationFilteredField.toString())));
}
request.setAttribute(PortalConstants.DATE_RANGE, nullToEmpty(request.getParameter(PortalConstants.DATE_RANGE)));
request.setAttribute(PortalConstants.END_DATE, nullToEmpty(request.getParameter(PortalConstants.END_DATE)));
super.doView(request, response);
}
use of org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest in project sw360 by eclipse.
the class ModerationPortletUtils method updateClearingRequest.
public static AddDocumentRequestSummary updateClearingRequest(PortletRequest request, Logger log) {
String id = request.getParameter(PortalConstants.CLEARING_REQUEST_ID);
User user = UserCacheHolder.getUserFromRequest(request);
String isReOpen = request.getParameter(PortalConstants.RE_OPEN_REQUEST);
AddDocumentRequestSummary requestSummary = new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.FAILURE);
if (null != id) {
if (CommonUtils.isNotNullEmptyOrWhitespace(isReOpen) && Boolean.parseBoolean(isReOpen)) {
return reOpenClearingRequest(id, request, user);
}
try {
String isClearingExpertEdit = request.getParameter(PortalConstants.IS_CLEARING_EXPERT);
ModerationService.Iface client = new ThriftClients().makeModerationClient();
ClearingRequest clearingRequest = client.getClearingRequestByIdForEdit(id, user);
String clearingTeam = request.getParameter(ClearingRequest._Fields.CLEARING_TEAM.toString());
if (CommonUtils.isNullEmptyOrWhitespace(clearingTeam)) {
log.warn("Invalid clearingTeam email: " + clearingTeam + " is entered, by user: " + user.getEmail());
return requestSummary.setMessage("Invalid clearingTeam email");
}
clearingRequest.setClearingTeam(clearingTeam);
if (CommonUtils.isNotNullEmptyOrWhitespace(isClearingExpertEdit) && Boolean.parseBoolean(isClearingExpertEdit)) {
String agreedDate = request.getParameter(ClearingRequest._Fields.AGREED_CLEARING_DATE.toString());
String status = request.getParameter(ClearingRequest._Fields.CLEARING_STATE.toString());
String priority = request.getParameter(ClearingRequest._Fields.PRIORITY.toString());
if (CommonUtils.isNotNullEmptyOrWhitespace(agreedDate) && !agreedDate.equals(clearingRequest.getAgreedClearingDate()) && !SW360Utils.isValidDate(agreedDate, DateTimeFormatter.ISO_LOCAL_DATE, null)) {
log.warn("Invalid agreed clearing date: " + agreedDate + " is entered, by user: " + user.getEmail());
return requestSummary.setMessage("Invalid agreed clearing date");
}
clearingRequest.setAgreedClearingDate(CommonUtils.nullToEmptyString(agreedDate));
clearingRequest.setClearingState(ClearingRequestState.findByValue(parseInt(status)));
clearingRequest.setPriority(ClearingRequestPriority.findByValue(parseInt(priority)));
}
LiferayPortletURL projectUrl = getProjectPortletUrl(request, clearingRequest.getProjectId());
RequestStatus status = client.updateClearingRequest(clearingRequest, user, CommonUtils.nullToEmptyString(projectUrl));
if (RequestStatus.SUCCESS.equals(status)) {
return new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.SUCCESS).setId(id);
} else {
return requestSummary.setMessage("Failed to update clearing request");
}
} catch (TException e) {
log.error("Failed to update clearing request", e);
}
}
log.error("Invalid clearing request Id.");
return requestSummary.setMessage("Invalid clearing request id");
}
use of org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest in project sw360 by eclipse.
the class ModerationPortletUtils method reOpenClearingRequest.
private static AddDocumentRequestSummary reOpenClearingRequest(String id, PortletRequest request, User user) {
AddDocumentRequestSummary requestSummary = new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.FAILURE);
try {
ModerationService.Iface client = new ThriftClients().makeModerationClient();
Integer criticalCount = client.getCriticalClearingRequestCount();
String preferredDate = request.getParameter(ClearingRequest._Fields.REQUESTED_CLEARING_DATE.toString());
String commentText = request.getParameter(ClearingRequest._Fields.REQUESTING_USER_COMMENT.toString());
String priority = (criticalCount > 1) ? "" : request.getParameter(ClearingRequest._Fields.PRIORITY.toString());
Integer dateLimit = ModerationPortletUtils.loadPreferredClearingDateLimit(request, user);
dateLimit = (CommonUtils.isNotNullEmptyOrWhitespace(priority) && criticalCount < 2) ? 0 : (dateLimit < 1) ? 7 : dateLimit;
if (!SW360Utils.isValidDate(preferredDate, DateTimeFormatter.ISO_LOCAL_DATE, Long.valueOf(dateLimit))) {
log.warn("Invalid requested clearing date: " + preferredDate + " is entered, by user: " + user.getEmail());
return requestSummary.setMessage("Invalid requested clearing date");
}
ClearingRequest clearingRequest = client.getClearingRequestByIdForEdit(id, user);
if (CommonUtils.isNotNullEmptyOrWhitespace(commentText)) {
commentText = "Reopen comment:\n" + commentText;
Comment comment = new Comment(commentText, user.getEmail());
comment.setAutoGenerated(true);
comment.setCommentedOn(System.currentTimeMillis());
clearingRequest.addToComments(comment);
}
clearingRequest.setRequestedClearingDate(preferredDate);
clearingRequest.unsetAgreedClearingDate();
clearingRequest.setClearingState(ClearingRequestState.NEW);
clearingRequest.unsetTimestampOfDecision();
if (CommonUtils.isNotNullEmptyOrWhitespace(priority)) {
clearingRequest.setPriority(ClearingRequestPriority.CRITICAL);
} else {
clearingRequest.setPriority(ClearingRequestPriority.LOW);
}
clearingRequest.addToReOpenOn(System.currentTimeMillis());
LiferayPortletURL projectUrl = getProjectPortletUrl(request, clearingRequest.getProjectId());
RequestStatus status = client.updateClearingRequest(clearingRequest, user, CommonUtils.nullToEmptyString(projectUrl));
if (RequestStatus.SUCCESS.equals(status)) {
return new AddDocumentRequestSummary().setRequestStatus(AddDocumentRequestStatus.SUCCESS).setId(id);
} else {
return requestSummary.setMessage("Failed to reopen clearing request");
}
} catch (TException e) {
log.error("Failed to re-open clearing request", e);
}
return requestSummary.setMessage("Failed to reopen clearing request");
}
use of org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest in project sw360 by eclipse.
the class ModerationDatabaseHandler method updateClearingRequestForProjectDeletion.
public void updateClearingRequestForProjectDeletion(Project project, User user) {
ClearingRequest clearingRequest = clearingRequestRepository.get(project.getClearingRequestId());
Comment comment = new Comment().setText(new StringBuilder("Clearing Request is orphaned, as project (name): <b>").append(SW360Utils.printName(project)).append("</b> associated with CR is deleted!").toString());
comment.setCommentedBy(user.getEmail());
comment.setAutoGenerated(true);
comment.setCommentedOn(System.currentTimeMillis());
clearingRequest.unsetProjectId();
clearingRequest.addToComments(comment);
clearingRequest.setModifiedOn(System.currentTimeMillis());
clearingRequest.unsetPriority();
clearingRequestRepository.update(clearingRequest);
}
Aggregations