SharedResource { @GET @Path("{workspaceId}/documents/{documentId}-{documentVersion}") @ApiOperation(value = "Get public shared document revision", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getPublicSharedDocumentRevision( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Document master id") @PathParam("documentId") String documentId, @ApiParam(required = true, value = "Document version") @PathParam("documentVersion") String documentVersion) throws AccessRightException, NotAllowedException, EntityNotFoundException, UserNotActiveException, WorkspaceNotEnabledException { DocumentRevisionKey docKey = new DocumentRevisionKey(workspaceId, documentId, documentVersion); DocumentRevision documentRevision = publicEntityManager.getPublicDocumentRevision(docKey); if (documentRevision == null && contextManager.isCallerInRole(UserGroupMapping.REGULAR_USER_ROLE_ID)) { documentRevision = documentManager.getDocumentRevision(docKey); } if (documentRevision != null) { DocumentRevisionDTO documentRevisionDTO = mapper.map(documentRevision, DocumentRevisionDTO.class); documentRevisionDTO.setRoutePath(documentRevision.getLocation().getRoutePath()); String entityToken = JWTokenFactory.createEntityToken(authConfig.getJWTKey(), documentRevision.getKey().toString()); return Response.ok().header("entity-token", entityToken).entity(documentRevisionDTO).build(); } else { return Response.status(Response.Status.FORBIDDEN).build(); } } SharedResource(); @PostConstruct void init(); @GET @Path("{workspaceId}/documents/{documentId}-{documentVersion}") @ApiOperation(value = "Get shared document revision", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPublicSharedDocumentRevision(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Document master id") @PathParam("documentId") String documentId,
            @ApiParam(required = true, value = "Document version") @PathParam("documentVersion") String documentVersion); @GET @Path("{workspaceId}/parts/{partNumber}-{partVersion}") @ApiOperation(value = "Get shared part revision", response = PartRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPublicSharedPartRevision(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Part number") @PathParam("partNumber") String partNumber,
            @ApiParam(required = true, value = "Part version") @PathParam("partVersion") String partVersion); @GET @Path("{uuid}/documents") @ApiOperation(value = "Get shared document from resource token", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getDocumentWithSharedEntity(
            @ApiParam(required = false, value = "Password for resource") @HeaderParam("password") String password,
            @ApiParam(required = true, value = "Resource token") @PathParam("uuid") String uuid); @GET @Path("{uuid}/parts") @ApiOperation(value = "Get shared part from resource token", response = PartRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of PartRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPartWithSharedEntity(
            @ApiParam(required = false, value = "Password for resource") @HeaderParam("password") String password,
            @ApiParam(required = true, value = "Resource token") @PathParam("uuid") String uuid);  }
@Test public void getPublicSharedDocumentRevisionTest() throws ApplicationException { DocumentRevisionKey docKey = new DocumentRevisionKey(workspaceId, documentId, documentVersion); DocumentRevision documentRevision = new DocumentRevision(); documentRevision.setLocation(new Folder(workspaceId, "somepath")); Mockito.when(publicEntityManager.getPublicDocumentRevision(docKey)) .thenReturn(null); Response response = sharedResource.getPublicSharedDocumentRevision(workspaceId, documentId, documentVersion); Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus()); Mockito.when(documentManager.getDocumentRevision(docKey)) .thenReturn(null); Mockito.when(contextManager.isCallerInRole(UserGroupMapping.REGULAR_USER_ROLE_ID)) .thenReturn(true); response = sharedResource.getPublicSharedDocumentRevision(workspaceId, documentId, documentVersion); Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus()); Mockito.when(publicEntityManager.getPublicDocumentRevision(docKey)) .thenReturn(documentRevision); response = sharedResource.getPublicSharedDocumentRevision(workspaceId, documentId, documentVersion); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }