Search in sources :

Example 6 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class ProjectRepository method filterAccessibleProjectsByIds.

@NotNull
private Set<Project> filterAccessibleProjectsByIds(User user, Set<String> searchIds) {
    final Set<Project> accessibleProjects = getAccessibleProjects(user);
    final Set<Project> output = new HashSet<>();
    for (Project accessibleProject : accessibleProjects) {
        if (searchIds.contains(accessibleProject.getId()))
            output.add(accessibleProject);
    }
    return output;
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class RepositoryUtils method doBulk.

// This works with any repository
public static RequestSummary doBulk(Collection<?> objects, User user, DatabaseRepository<?> repository) {
    RequestSummary requestSummary = new RequestSummary();
    if (PermissionUtils.isAdmin(user)) {
        // Prepare component for database
        final List<DocumentOperationResult> documentOperationResults = repository.executeBulk(objects);
        requestSummary.setTotalElements(objects.size());
        requestSummary.setTotalAffectedElements(objects.size() - documentOperationResults.size());
        requestSummary.setRequestStatus(RequestStatus.SUCCESS);
    } else {
        requestSummary.setRequestStatus(RequestStatus.FAILURE);
    }
    return requestSummary;
}
Also used : RequestSummary(org.eclipse.sw360.datahandler.thrift.RequestSummary) DocumentOperationResult(org.ektorp.DocumentOperationResult)

Example 8 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class ComponentRepository method getRecentComponentsSummary.

public List<Component> getRecentComponentsSummary(int limit, User user) {
    ViewQuery query = createQuery("byCreatedOn").includeDocs(true).descending(true);
    if (limit >= 0) {
        query.limit(limit);
    }
    List<Component> components = db.queryView(query, Component.class);
    return makeSummaryWithPermissionsFromFullDocs(SummaryType.SUMMARY, components, user);
}
Also used : ViewQuery(org.ektorp.ViewQuery) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 9 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class ComponentController method getComponent.

@RequestMapping(value = COMPONENTS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Component>> getComponent(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
    User user = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    Component sw360Component = componentService.getComponentForUserById(id, user);
    HalResource<Component> userHalResource = createHalComponent(sw360Component, user);
    return new ResponseEntity<>(userHalResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Example 10 with User

use of org.eclipse.sw360.datahandler.thrift.users.User in project sw360portal by sw360.

the class ComponentController method downloadAttachmentFromComponent.

@RequestMapping(value = COMPONENTS_URL + "/{componentId}/attachments/{attachmentId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void downloadAttachmentFromComponent(@PathVariable("componentId") String componentId, @PathVariable("attachmentId") String attachmentId, HttpServletResponse response, OAuth2Authentication oAuth2Authentication) throws TException {
    final User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    final Component component = componentService.getComponentForUserById(componentId, sw360User);
    attachmentService.downloadAttachmentWithContext(component, attachmentId, response, oAuth2Authentication);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Component(org.eclipse.sw360.datahandler.thrift.components.Component)

Aggregations

User (org.eclipse.sw360.datahandler.thrift.users.User)169 TException (org.apache.thrift.TException)100 Release (org.eclipse.sw360.datahandler.thrift.components.Release)58 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)44 Test (org.junit.Test)30 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)27 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)26 Component (org.eclipse.sw360.datahandler.thrift.components.Component)20 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)20 ResponseEntity (org.springframework.http.ResponseEntity)20 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)19 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)18 IOException (java.io.IOException)17 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)16 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)16 HalResource (org.eclipse.sw360.rest.resourceserver.core.HalResource)13 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)12 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)12 Before (org.junit.Before)12 ArrayList (java.util.ArrayList)11