use of org.eclipse.sw360.datahandler.thrift.ThriftClients 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.ThriftClients in project sw360portal by sw360.
the class DisplayProjectChanges method renderProjectLinkListCompare.
private void renderProjectLinkListCompare(StringBuilder display, Map<String, ProjectRelationship> oldProjectRelationshipMap, Map<String, ProjectRelationship> deleteProjectRelationshipMap, Map<String, ProjectRelationship> updateProjectRelationshipMap, Set<String> projectIds, User user) {
if (projectIds.isEmpty())
return;
StringBuilder candidate = new StringBuilder();
try {
ProjectService.Iface client = new ThriftClients().makeProjectClient();
Map<String, ProjectRelationship> changeMap = new HashMap<>();
for (String projectId : projectIds) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectId);
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectId);
if (!updateProjectRelationship.equals(oldProjectRelationship)) {
changeMap.put(projectId, oldProjectRelationshipMap.get(projectId));
}
}
// ! This code doubling is done to reduce the database queries. I.e. one big query instead of multiple small ones
for (ProjectLink projectLink : client.getLinkedProjects(changeMap, user)) {
ProjectRelationship updateProjectRelationship = updateProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship deleteProjectRelationship = deleteProjectRelationshipMap.get(projectLink.getId());
ProjectRelationship oldProjectRelationship = oldProjectRelationshipMap.get(projectLink.getId());
candidate.append(String.format("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", projectLink.getName(), oldProjectRelationship, deleteProjectRelationship, updateProjectRelationship));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%sUpdated\" >", tableClasses, idPrefix));
display.append("<thead><tr><th colspan=\"4\">Updated Project Links</th></tr>" + "<tr><th>Project Name</th>" + "<th>Current Project Relationship</th>" + "<th>Deleted Project Relationship</th>" + "<th>Suggested Project Relationship</th></tr>" + "</thead><tbody>");
display.append(tableContent);
display.append("</tbody></table>");
}
}
use of org.eclipse.sw360.datahandler.thrift.ThriftClients in project sw360portal by sw360.
the class DisplayProjectChanges method renderProjectLinkList.
private void renderProjectLinkList(StringBuilder display, Map<String, ProjectRelationship> projectRelationshipMap, Set<String> projectIds, String msg, User user) {
if (projectIds.isEmpty())
return;
Map<String, ProjectRelationship> filteredMap = new HashMap<>();
for (String id : projectIds) {
filteredMap.put(id, projectRelationshipMap.get(id));
}
StringBuilder candidate = new StringBuilder();
try {
ProjectService.Iface client = new ThriftClients().makeProjectClient();
for (ProjectLink projectLink : client.getLinkedProjects(filteredMap, user)) {
candidate.append(String.format("<tr><td>%s</td><td>%s</td></tr>", projectLink.getName(), projectLink.getRelation()));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%s%s\" >", tableClasses, idPrefix, msg));
display.append(String.format("<thead><tr><th colspan=\"2\">%s</th></tr>" + "<tr><th>Project Name</th><th>Project Relationship</th></tr></thead><tbody>", msg));
display.append(tableContent);
display.append("</tbody></table>");
}
}
use of org.eclipse.sw360.datahandler.thrift.ThriftClients in project sw360portal by sw360.
the class LinkedReleaseRenderer method renderReleaseLinkList.
public <T> void renderReleaseLinkList(StringBuilder display, Map<String, T> releaseRelationshipMap, Set<String> releaseIds, String msg) {
if (releaseIds.isEmpty())
return;
StringBuilder candidate = new StringBuilder();
try {
ComponentService.Iface componentClient = new ThriftClients().makeComponentClient();
for (Release release : componentClient.getReleasesById(releaseIds, user)) {
candidate.append(String.format("<tr><td>%s</td><td>%s</td></tr>", release.getName(), releaseRelationshipMap.get(release.getId())));
}
} catch (TException ignored) {
}
String tableContent = candidate.toString();
if (!tableContent.isEmpty()) {
display.append(String.format("<table class=\"%s\" id=\"%s%s\" >", tableClasses, idPrefix, msg));
display.append(String.format("<thead><tr><th colspan=\"2\">%s</th></tr><tr><th>Release name</th><th>Release relationship</th></tr></thead><tbody>", msg));
display.append(tableContent);
display.append("</tbody></table>");
}
}
use of org.eclipse.sw360.datahandler.thrift.ThriftClients in project sw360portal by sw360.
the class UserAwareTag method getUserFromContext.
protected User getUserFromContext(String errorMessage) throws JspException, TException {
Optional<String> userEmailOpt = UserCacheHolder.getUserEmailFromRequest(pageContext.getRequest());
String userEmail = userEmailOpt.orElseThrow(() -> new JspException(errorMessage));
UserService.Iface userClient = new ThriftClients().makeUserClient();
return userClient.getByEmail(userEmail);
}
Aggregations