use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ProjectPortlet method prepareProjectEdit.
private void prepareProjectEdit(RenderRequest request) {
User user = UserCacheHolder.getUserFromRequest(request);
String id = request.getParameter(PROJECT_ID);
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
Project project;
Set<Project> usingProjects;
request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());
if (id != null) {
try {
ProjectService.Iface client = thriftClients.makeProjectClient();
project = client.getProjectByIdForEdit(id, user);
usingProjects = client.searchLinkingProjects(id, user);
} catch (TException e) {
log.error("Something went wrong with fetching the project", e);
setSW360SessionError(request, ErrorMessages.ERROR_GETTING_PROJECT);
return;
}
request.setAttribute(PROJECT, project);
request.setAttribute(DOCUMENT_ID, id);
setAttachmentsInRequest(request, project.getAttachments());
try {
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
} catch (TException e) {
log.error("Could not fetch linked projects or linked releases in projects view.", e);
return;
}
request.setAttribute(USING_PROJECTS, usingProjects);
Map<RequestedAction, Boolean> permissions = project.getPermissions();
DocumentState documentState = project.getDocumentState();
addEditDocumentMessage(request, permissions, documentState);
} else {
if (request.getAttribute(PROJECT) == null) {
project = new Project();
project.setBusinessUnit(user.getDepartment());
request.setAttribute(PROJECT, project);
setAttachmentsInRequest(request, project.getAttachments());
try {
putDirectlyLinkedProjectsInRequest(request, project, user);
putDirectlyLinkedReleasesInRequest(request, project);
} catch (TException e) {
log.error("Could not put empty linked projects or linked releases in projects view.", e);
}
request.setAttribute(USING_PROJECTS, Collections.emptySet());
SessionMessages.add(request, "request_processed", "New Project");
}
}
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class LicenseDatabaseHandler method getLicenseForOrganisationWithOwnModerationRequests.
public License getLicenseForOrganisationWithOwnModerationRequests(String id, String organisation, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
License license = getLicenseForOrganisation(id, organisation);
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();
license = moderator.updateLicenseFromModerationRequest(license, moderationRequest.getLicenseAdditions(), moderationRequest.getLicenseDeletions(), organisation);
for (Todo todo : license.getTodos()) {
// remove other organisations from whitelist of todo
todo.setWhitelist(SW360Utils.filterBUSet(organisation, todo.whitelist));
}
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
license.setPermissions(makePermission(license, user).getPermissionMap());
license.setDocumentState(documentState);
return license;
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class CommonUtils method getModeratedDocumentState.
@NotNull
public static DocumentState getModeratedDocumentState(ModerationRequest moderationRequest) {
DocumentState documentState = new DocumentState().setIsOriginalDocument(false);
documentState.setModerationState(moderationRequest.getModerationState());
return documentState;
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class CommonUtils method getOriginalDocumentState.
@NotNull
public static DocumentState getOriginalDocumentState() {
DocumentState documentState = new DocumentState().setIsOriginalDocument(true);
documentState.unsetModerationState();
return documentState;
}
use of org.eclipse.sw360.datahandler.thrift.DocumentState in project sw360portal by sw360.
the class ComponentDatabaseHandler method getComponentForEdit.
public Component getComponentForEdit(String id, User user) throws SW360Exception {
List<ModerationRequest> moderationRequestsForDocumentId = moderator.getModerationRequestsForDocumentId(id);
Component component = getComponent(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();
component = moderator.updateComponentFromModerationRequest(component, moderationRequest.getComponentAdditions(), moderationRequest.getComponentDeletions());
documentState = CommonUtils.getModeratedDocumentState(moderationRequest);
} else {
documentState = new DocumentState().setIsOriginalDocument(true).setModerationState(moderationRequestsForDocumentId.get(0).getModerationState());
}
}
component.setPermissions(makePermission(component, user).getPermissionMap());
component.setDocumentState(documentState);
return component;
}
Aggregations