Search in sources :

Example 6 with ThriftClients

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;
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) RequestedAction(org.eclipse.sw360.datahandler.thrift.users.RequestedAction) VendorService(org.eclipse.sw360.datahandler.thrift.vendors.VendorService)

Example 7 with ThriftClients

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 8 with ThriftClients

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ProjectLink(org.eclipse.sw360.datahandler.thrift.projects.ProjectLink) HashMap(java.util.HashMap) ProjectRelationship(org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship) ProjectService(org.eclipse.sw360.datahandler.thrift.projects.ProjectService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 9 with ThriftClients

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>");
    }
}
Also used : TException(org.apache.thrift.TException) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Example 10 with ThriftClients

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);
}
Also used : JspException(javax.servlet.jsp.JspException) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients)

Aggregations

TException (org.apache.thrift.TException)17 User (org.eclipse.sw360.datahandler.thrift.users.User)12 ThriftClients (org.eclipse.sw360.datahandler.thrift.ThriftClients)10 JspException (javax.servlet.jsp.JspException)3 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)3 HashMap (java.util.HashMap)2 JspWriter (javax.servlet.jsp.JspWriter)2 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 ProjectLink (org.eclipse.sw360.datahandler.thrift.projects.ProjectLink)2 ProjectRelationship (org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship)2 ProjectService (org.eclipse.sw360.datahandler.thrift.projects.ProjectService)2 UserService (org.eclipse.sw360.datahandler.thrift.users.UserService)2 VendorService (org.eclipse.sw360.datahandler.thrift.vendors.VendorService)2 Before (org.junit.Before)2 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AttachmentHandler (org.eclipse.sw360.attachments.AttachmentHandler)1 ComponentHandler (org.eclipse.sw360.components.ComponentHandler)1