Search in sources :

Example 21 with User

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

the class UserResourceProcessor method process.

@Override
public Resource<User> process(Resource<User> resource) {
    try {
        User user = resource.getContent();
        String userUUID = Base64.getEncoder().encodeToString(user.getEmail().getBytes("utf-8"));
        Link selfLink = linkTo(UserController.class).slash("api/users/" + userUUID).withSelfRel();
        resource.add(selfLink);
        return resource;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) Link(org.springframework.hateoas.Link)

Example 22 with User

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

the class Sw360VulnerabilityService method getVulnerabilityWithReleaseRelationsByExternalId.

public Vulnerability getVulnerabilityWithReleaseRelationsByExternalId(String externalId, User sw360User) {
    try {
        VulnerabilityService.Iface sw360VulnerabilityClient = getThriftVulnerabilityClient();
        final VulnerabilityWithReleaseRelations vulWithRel = sw360VulnerabilityClient.getVulnerabilityWithReleaseRelationsByExternalId(externalId, sw360User);
        return vulWithRel.getVulnerability();
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}
Also used : VulnerabilityWithReleaseRelations(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityWithReleaseRelations) TException(org.apache.thrift.TException) VulnerabilityService(org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityService)

Example 23 with User

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

the class ComponentTest method before.

@Before
public void before() throws TException {
    List<Component> componentList = new ArrayList<>();
    Component component = new Component();
    component.setName("Component name");
    component.setDescription("Component description");
    componentList.add(component);
    given(this.componentServiceMock.getComponentsForUser(anyObject())).willReturn(componentList);
    User user = new User();
    user.setId("admin@sw360.org");
    user.setEmail("admin@sw360.org");
    user.setFullname("John Doe");
    given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ArrayList(java.util.ArrayList) Component(org.eclipse.sw360.datahandler.thrift.components.Component) Before(org.junit.Before)

Example 24 with User

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

the class Sw360AttachmentService method downloadAttachmentWithContext.

public void downloadAttachmentWithContext(Object context, String attachmentId, HttpServletResponse response, OAuth2Authentication oAuth2Authentication) {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    AttachmentContent attachmentContent = getAttachmentContent(attachmentId);
    String filename = attachmentContent.getFilename();
    String contentType = attachmentContent.getContentType();
    try (InputStream attachmentStream = getStreamToAttachments(Collections.singleton(attachmentContent), sw360User, context)) {
        response.setContentType(contentType);
        response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
        FileCopyUtils.copy(attachmentStream, response.getOutputStream());
    } catch (TException | IOException e) {
        log.error(e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 25 with User

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

the class Sw360AttachmentService method uploadAttachment.

public Attachment uploadAttachment(MultipartFile file, Attachment newAttachment, User sw360User) throws IOException, TException {
    // TODO: shouldn't the fileName be taken from newAttachment?
    String fileName = file.getOriginalFilename();
    String contentType = file.getContentType();
    final AttachmentContent attachmentContent = makeAttachmentContent(fileName, contentType);
    final AttachmentConnector attachmentConnector = getConnector();
    Attachment attachment = new AttachmentFrontendUtils().uploadAttachmentContent(attachmentContent, file.getInputStream(), sw360User);
    attachment.setSha1(attachmentConnector.getSha1FromAttachmentContentId(attachmentContent.getId()));
    AttachmentType attachmentType = newAttachment.getAttachmentType();
    if (attachmentType != null) {
        attachment.setAttachmentType(attachmentType);
    }
    CheckStatus checkStatus = newAttachment.getCheckStatus();
    if (checkStatus != null) {
        attachment.setCheckStatus(checkStatus);
    }
    return attachment;
}
Also used : AttachmentFrontendUtils(org.eclipse.sw360.commonIO.AttachmentFrontendUtils) AttachmentConnector(org.eclipse.sw360.datahandler.couchdb.AttachmentConnector)

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