use of org.eclipse.sw360.datahandler.thrift.users.RequestedAction in project sw360portal by sw360.
the class ProjectDatabaseHandler method getReleaseIdsOfProjectTree.
private Set<String> getReleaseIdsOfProjectTree(Project project, Set<String> visitedProjectIds, Map<String, Project> allProjectsIdMap, User user, List<RequestedAction> permissionsFilter) {
// no need to visit a project twice
if (visitedProjectIds.contains(project.getId())) {
return Collections.emptySet();
}
// we are now checking this project so no need for further examination in
// recursion
visitedProjectIds.add(project.getId());
// container to aggregate results
Set<String> releaseIds = Sets.newHashSet();
// "DUPLICATE" and add the result to this result
if (project.isSetLinkedProjects()) {
project.getLinkedProjects().entrySet().stream().forEach(e -> {
if (!ProjectRelationship.REFERRED.equals(e.getValue()) && !ProjectRelationship.DUPLICATE.equals(e.getValue())) {
Project childProject = allProjectsIdMap.get(e.getKey());
if (childProject != null) {
// so do it now
if (permissionsFilter == null || permissionsFilter.isEmpty() || makePermission(childProject, user).areActionsAllowed(permissionsFilter)) {
// recursion inside :-)
releaseIds.addAll(getReleaseIdsOfProjectTree(childProject, visitedProjectIds, allProjectsIdMap, user, permissionsFilter));
}
}
}
});
}
// add own releases to result if they are not just "REFERRED"
if (project.isSetReleaseIdToUsage()) {
project.getReleaseIdToUsage().entrySet().stream().forEach(e -> {
if (!ReleaseRelationship.REFERRED.equals(e.getValue().getReleaseRelation())) {
releaseIds.add(e.getKey());
}
});
}
return releaseIds;
}
use of org.eclipse.sw360.datahandler.thrift.users.RequestedAction 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.users.RequestedAction in project sw360portal by sw360.
the class ComponentPortletUtils method deleteVendor.
public static RequestStatus deleteVendor(PortletRequest request, Logger log) {
String vendorId = request.getParameter(PortalConstants.VENDOR_ID);
if (vendorId != null) {
try {
User user = UserCacheHolder.getUserFromRequest(request);
ThriftClients thriftClients = new ThriftClients();
ComponentService.Iface componentClient = thriftClients.makeComponentClient();
VendorService.Iface client = thriftClients.makeVendorClient();
RequestStatus global_status = RequestStatus.SUCCESS;
List<Release> releases = componentClient.getReleasesFromVendorId(vendorId, user);
boolean mayWriteToAllReleases = true;
for (Release release : releases) {
Map<RequestedAction, Boolean> permissions = release.getPermissions();
mayWriteToAllReleases &= permissions.get(RequestedAction.WRITE);
}
if (!mayWriteToAllReleases) {
return RequestStatus.FAILURE;
}
for (Release release : releases) {
release.unsetVendorId();
RequestStatus local_status = componentClient.updateRelease(release, user);
if (local_status != RequestStatus.SUCCESS)
global_status = local_status;
}
if (global_status == RequestStatus.SUCCESS) {
return client.deleteVendor(vendorId, user);
} else {
return global_status;
}
} catch (TException e) {
log.error("Could not delete release from DB", e);
}
}
return RequestStatus.FAILURE;
}
use of org.eclipse.sw360.datahandler.thrift.users.RequestedAction 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.users.RequestedAction 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