use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ComponentDatabaseHandler method getReleaseForEdit.
public Release getReleaseForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Release release = getRelease(id, user);
DocumentState documentState;
if (moderationRequestsForDocumentId.isEmpty()) {
documentState = CommonUtils.getOriginalDocumentState();
} else {
final String email = user.getEmail();
Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
ModerationRequest moderationRequest = moderationRequestOptional.get();
release = releaseModerator.updateReleaseFromModerationRequest(release, moderationRequest.getReleaseAdditions(), moderationRequest.getReleaseDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
vendorRepository.fillVendor(release);
release.setPermissions(makePermission(release, user).getPermissionMap());
release.setDocumentState(documentState);
ensureEccInformationIsSet(release);
return release;
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ProjectDatabaseHandler method getProjectForEdit.
public Project getProjectForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Project project = getProjectById(id, user);
DocumentState documentState;
if (moderationRequestsForDocumentId.isEmpty()) {
documentState = CommonUtils.getOriginalDocumentState();
} else {
final String email = user.getEmail();
Optional<ModerationRequest> moderationRequestOptional = CommonUtils.getFirstModerationRequestOfUser(moderationRequestsForDocumentId, email);
if (moderationRequestOptional.isPresent() && isInProgressOrPending(moderationRequestOptional.get())) {
ModerationRequest moderationRequest = moderationRequestOptional.get();
project = moderator.updateProjectFromModerationRequest(project, moderationRequest.getProjectAdditions(), moderationRequest.getProjectDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
project.setPermissions(makePermission(project, user).getPermissionMap());
project.setDocumentState(documentState);
return project;
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ComponentPortlet method prepareReleaseEdit.
private void prepareReleaseEdit(RenderRequest request, RenderResponse response) throws PortletException {
String id = request.getParameter(COMPONENT_ID);
String releaseId = request.getParameter(RELEASE_ID);
final User user = UserCacheHolder.getUserFromRequest(request);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_RELEASE);
if (isNullOrEmpty(id) && isNullOrEmpty(releaseId)) {
throw new PortletException("Component or Release ID not set!");
}
try {
ComponentService.Iface client = thriftClients.makeComponentClient();
Release release;
if (!isNullOrEmpty(releaseId)) {
release = client.getReleaseByIdForEdit(releaseId, user);
request.setAttribute(RELEASE, release);
request.setAttribute(DOCUMENT_ID, releaseId);
setAttachmentsInRequest(request, release.getAttachments());
putDirectlyLinkedReleaseRelationsInRequest(request, release);
Map<RequestedAction, Boolean> permissions = release.getPermissions();
DocumentState documentState = release.getDocumentState();
setUsingDocs(request, releaseId, user, client);
addEditDocumentMessage(request, permissions, documentState);
if (isNullOrEmpty(id)) {
id = release.getComponentId();
}
} else {
release = (Release) request.getAttribute(RELEASE);
if (release == null) {
release = new Release();
release.setComponentId(id);
release.setClearingState(ClearingState.NEW_CLEARING);
request.setAttribute(RELEASE, release);
putDirectlyLinkedReleaseRelationsInRequest(request, release);
setAttachmentsInRequest(request, release.getAttachments());
setUsingDocs(request, null, user, client);
SessionMessages.add(request, "request_processed", "New Release");
}
}
Component component = client.getComponentById(id, user);
addComponentBreadcrumb(request, response, component);
if (!isNullOrEmpty(release.getId())) {
// Otherwise the link is meaningless
addReleaseBreadcrumb(request, response, release);
}
request.setAttribute(COMPONENT, component);
request.setAttribute(IS_USER_AT_LEAST_ECC_ADMIN, PermissionUtils.isUserAtLeast(UserGroup.ECC_ADMIN, user) ? "Yes" : "No");
} catch (TException e) {
log.error("Error fetching release from backend!", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_RELEASE);
}
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ComponentPortlet method prepareComponentEdit.
private void prepareComponentEdit(RenderRequest request) {
String id = request.getParameter(COMPONENT_ID);
final User user = UserCacheHolder.getUserFromRequest(request);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_COMPONENT);
if (id != null) {
try {
ComponentService.Iface client = thriftClients.makeComponentClient();
Component component = client.getComponentByIdForEdit(id, user);
request.setAttribute(COMPONENT, component);
request.setAttribute(DOCUMENT_ID, id);
setAttachmentsInRequest(request, component.getAttachments());
Map<RequestedAction, Boolean> permissions = component.getPermissions();
DocumentState documentState = component.getDocumentState();
addEditDocumentMessage(request, permissions, documentState);
Set<String> releaseIds = SW360Utils.getReleaseIds(component.getReleases());
setUsingDocs(request, user, client, releaseIds);
} catch (TException e) {
log.error("Error fetching component from backend!", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_COMPONENT);
}
} else {
if (request.getAttribute(COMPONENT) == null) {
Component component = new Component();
request.setAttribute(COMPONENT, component);
setUsingDocs(request, user, null, component.getReleaseIds());
setAttachmentsInRequest(request, component.getAttachments());
SessionMessages.add(request, "request_processed", "New Component");
}
}
}
Aggregations