Search in sources :

Example 11 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 12 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 13 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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 14 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component 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)

Example 15 with Component

use of org.eclipse.sw360.datahandler.thrift.components.Component in project sw360portal by sw360.

the class Sw360ComponentService method updateComponent.

public RequestStatus updateComponent(Component component, User sw360User) throws TException {
    ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
    RequestStatus requestStatus = sw360ComponentClient.updateComponent(component, sw360User);
    if (requestStatus != RequestStatus.SUCCESS) {
        throw new RuntimeException("sw360 component with name '" + component.getName() + " cannot be updated.");
    }
    return requestStatus;
}
Also used : ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) AddDocumentRequestStatus(org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus)

Aggregations

Component (org.eclipse.sw360.datahandler.thrift.components.Component)38 User (org.eclipse.sw360.datahandler.thrift.users.User)30 TException (org.apache.thrift.TException)23 Release (org.eclipse.sw360.datahandler.thrift.components.Release)23 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)10 TestUtils.assertTestString (org.eclipse.sw360.datahandler.TestUtils.assertTestString)8 Before (org.junit.Before)7 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)6 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)5 Vendor (org.eclipse.sw360.datahandler.thrift.vendors.Vendor)5 IOException (java.io.IOException)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 Test (org.junit.Test)4 ModerationRequest (org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest)3 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)3 FluentIterable (com.google.common.collect.FluentIterable)2 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2