use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ComponentSearchHandlerTest method setUp.
@Before
public void setUp() throws Exception {
assumeCanConnectTo(ThriftClients.BACKEND_URL + "/couchdblucene/");
components = new ArrayList<>();
Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setCreatedBy(email1);
component1.addToLanguages("C");
component1.addToCategories("library");
component1.addToOperatingSystems("linux");
component1.addToSoftwarePlatforms("boost");
component1.addToReleaseIds("R1A");
component1.addToReleaseIds("R1B");
component1.addToVendorNames("V1");
components.add(component1);
Component component2 = new Component().setId("C2").setName("component2").setDescription("d2").setCreatedBy(email2);
component2.addToLanguages("D");
component2.addToLanguages("C");
component2.addToCategories("test");
component2.addToOperatingSystems("test");
component2.addToSoftwarePlatforms("test");
component2.addToReleaseIds("R2A");
component2.addToReleaseIds("R2B");
component2.addToReleaseIds("R2C");
component1.addToVendorNames("V2");
components.add(component2);
Component component3 = new Component().setId("C3").setName("component3").setDescription("d3").setCreatedBy(email1);
component3.addToSubscribers(email1);
component3.addToLanguages("E");
components.add(component3);
// Create the database
TestUtils.createDatabase(DatabaseSettings.getConfiguredHttpClient(), dbName);
// Prepare the database
DatabaseConnector databaseConnector = new DatabaseConnector(DatabaseSettings.getConfiguredHttpClient(), dbName);
for (Component component : components) {
databaseConnector.add(component);
}
// Prepare the handler
searchHandler = new ComponentSearchHandler(DatabaseSettings.getConfiguredHttpClient(), dbName);
}
use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.
the class ProjectDatabaseHandler method getReleaseClearingStatuses.
public List<ReleaseClearingStatusData> getReleaseClearingStatuses(String projectId, User user) throws SW360Exception {
Project project = getProjectById(projectId, user);
SetMultimap<String, ProjectWithReleaseRelationTuple> releaseIdsToProject = releaseIdToProjects(project, user);
List<Release> releasesById = componentDatabaseHandler.getFullReleases(releaseIdsToProject.keySet());
Map<String, Component> componentsById = ThriftUtils.getIdMap(componentDatabaseHandler.getComponentsShort(releasesById.stream().map(Release::getComponentId).collect(Collectors.toSet())));
List<ReleaseClearingStatusData> releaseClearingStatuses = new ArrayList<>();
for (Release release : releasesById) {
List<String> projectNames = new ArrayList<>();
List<String> mainlineStates = new ArrayList<>();
for (ProjectWithReleaseRelationTuple projectWithReleaseRelation : releaseIdsToProject.get(release.getId())) {
projectNames.add(printName(projectWithReleaseRelation.getProject()));
mainlineStates.add(ThriftEnumUtils.enumToString(projectWithReleaseRelation.getRelation().getMainlineState()));
if (projectNames.size() > 3) {
projectNames.add("...");
mainlineStates.add("...");
break;
}
}
releaseClearingStatuses.add(new ReleaseClearingStatusData(release).setProjectNames(joinStrings(projectNames)).setMainlineStates(joinStrings(mainlineStates)).setComponentType(componentsById.get(release.getComponentId()).getComponentType()));
}
return releaseClearingStatuses;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component 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;
}
use of org.eclipse.sw360.datahandler.thrift.components.Component 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.components.Component in project sw360portal by sw360.
the class ComponentPortlet method prepareComponentMerge.
private void prepareComponentMerge(RenderRequest request, RenderResponse response) throws PortletException {
final User user = UserCacheHolder.getUserFromRequest(request);
String componentId = request.getParameter(COMPONENT_ID);
if (isNullOrEmpty(componentId)) {
throw new PortletException("Component ID not set!");
}
try {
ComponentService.Iface client = thriftClients.makeComponentClient();
Component component = client.getComponentById(componentId, user);
request.setAttribute(COMPONENT, component);
addComponentBreadcrumb(request, response, component);
PortletURL mergeUrl = response.createRenderURL();
mergeUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_MERGE_COMPONENT);
mergeUrl.setParameter(PortalConstants.COMPONENT_ID, componentId);
addBreadcrumbEntry(request, "Merge", mergeUrl);
} catch (TException e) {
log.error("Error fetching release from backend!", e);
}
}
Aggregations