/** Returns the status of each health check. @return 200 */ @GET @Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8") @Path("status") public Response status() { List<String> messages = new ArrayList<String>(); for (HealthStatus healthCheck : m_healthCheckService.getChecks()) { HealthCheck.Result result = healthCheck.execute(); if (result.isHealthy()) { messages.add(healthCheck.getName() + ": OK"); } else { messages.add(healthCheck.getName() + ": FAIL"); } } GenericEntity<List<String>> entity = new GenericEntity<List<String>>(messages) { }; return setHeaders(Response.ok(entity)).build(); }
@GET @Path("conversations") @Secure public Response getConversations() { List<Conversation> conversations = new ArrayList<>(); Cursor cur = deskDroidService.getApplication().getContentResolver() .query(Telephony.Sms.Conversations.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { conversations.add(buildConversation(cur)); } cur.close(); Collections.sort(conversations, new ConversationComparator()); return Response.ok(new GenericEntity<List<Conversation>>(conversations) { }).build(); }
@Override public Response toResponse(JaxbException exception) { int errorCode = 1; String errorMsg = "JAXB convert/validate error, please check your input data"; if (config != null) { Object propErrorCode = config.getProperty(PROP_JAXB_DEFAULT_ERROR_CODE); Object propErrorMsg = config.getProperty(PROP_JAXB_DEFAULT_ERROR_MSG); if (propErrorCode != null) { errorCode = Integer.valueOf(propErrorCode.toString()); } if (propErrorMsg != null) { errorMsg = propErrorMsg.toString(); } } List<JaxbError> errors = new ArrayList<>(); errors.add(new JaxbError(exception.getMessage())); ParsecErrorResponse<JaxbError> errorResponse = ValidateUtil.buildErrorResponse(errors, errorCode, errorMsg); return Response.status(Response.Status.BAD_REQUEST) .entity(new GenericEntity<ParsecErrorResponse<JaxbError>>(errorResponse) { }).build(); }
@GET @Path("/providers") @ApiOperation(value = "Get supported providers", response = OAuthProviderPublicDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of providers. It can be an empty list."), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getProviders() { List<OAuthProvider> providers = oAuthManager.getProviders(); List<OAuthProviderPublicDTO> dtos = new ArrayList<>(); for (OAuthProvider provider : providers) { OAuthProviderPublicDTO oAuthProviderPublicDTO = mapper.map(provider, OAuthProviderPublicDTO.class); oAuthProviderPublicDTO.setSigningKeys(getSigningKeys(provider.getJwkSetURL())); dtos.add(oAuthProviderPublicDTO); } // need to get jwks signing keys (they can be changed) return Response.ok(new GenericEntity<List<OAuthProviderPublicDTO>>(dtos) { }).build(); }
@GET @Path("providers") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of auth providers"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @ApiOperation(value = "Get detailed providers", response = OAuthProviderDTO.class, responseContainer = "List") @Produces(MediaType.APPLICATION_JSON) public Response getDetailedProviders() { List<OAuthProvider> providers = oAuthManager.getProviders(); List<OAuthProviderDTO> dtos = new ArrayList<>(); for (OAuthProvider provider : providers) { dtos.add(mapper.map(provider, OAuthProviderDTO.class)); } return Response.ok(new GenericEntity<List<OAuthProviderDTO>>(dtos) { }).build(); }
@GET @ApiOperation(value = "Get product-instance's iterations", response = ProductInstanceIterationDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductInstanceMasterDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("{ciId}/instances/{serialNumber}/iterations") @Produces(MediaType.APPLICATION_JSON) public Response getProductInstanceIterations( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Configuration item id") @PathParam("ciId") String configurationItemId, @ApiParam(required = true, value = "Serial number") @PathParam("serialNumber") String serialNumber) throws EntityNotFoundException, UserNotActiveException { List<ProductInstanceIteration> productInstanceIterationList = productInstanceService.getProductInstanceIterations(new ProductInstanceMasterKey(serialNumber, workspaceId, configurationItemId)); List<ProductInstanceIterationDTO> productInstanceIterationDTOs = new ArrayList<>(); for (ProductInstanceIteration productInstanceIteration : productInstanceIterationList) { ProductInstanceIterationDTO productInstanceIterationDTO = mapper.map(productInstanceIteration, ProductInstanceIterationDTO.class); productInstanceIterationDTOs.add(productInstanceIterationDTO); } return Response.ok(new GenericEntity<List<ProductInstanceIterationDTO>>((List<ProductInstanceIterationDTO>) productInstanceIterationDTOs) { }).build(); }
@GET @Path("members") @ApiOperation(value = "Get members of the authenticated user's organization", response = AccountDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of AccountDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getMembers() throws AccountNotFoundException, OrganizationNotFoundException, AccessRightException { Organization organization = organizationManager.getMyOrganization(); List<Account> accounts = organization.getMembers(); List<AccountDTO> accountsDTOs = new ArrayList<>(); for (Account account : accounts) { accountsDTOs.add(mapper.map(account, AccountDTO.class)); } return Response.ok(new GenericEntity<List<AccountDTO>>((List<AccountDTO>) accountsDTOs) { }).build(); }
@GET @ApiOperation(value = "Get orders for given parameters", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getOrders( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { List<ChangeOrder> changeOrders = changeManager.getChangeOrders(workspaceId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder order : changeOrders) { ChangeOrderDTO changeOrderDTO = mapper.map(order, ChangeOrderDTO.class); changeOrderDTO.setWritable(changeManager.isChangeItemWritable(order)); changeOrderDTOs.add(changeOrderDTO); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); }
@GET @ApiOperation(value = "Get tags in workspace", response = TagDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of TagDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getTagsInWorkspace( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { String[] tagsName = documentService.getTags(workspaceId); List<TagDTO> tagsDTO = new ArrayList<>(); for (String tagName : tagsName) { tagsDTO.add(new TagDTO(tagName, workspaceId)); } return Response.ok(new GenericEntity<List<TagDTO>>((List<TagDTO>) tagsDTO) { }).build(); }
@GET @ApiOperation(value = "Get milestones for given parameters", response = MilestoneDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of MilestoneDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getMilestones( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { List<Milestone> milestones = changeManager.getMilestones(workspaceId); List<MilestoneDTO> milestoneDTOs = new ArrayList<>(); for (Milestone milestone : milestones) { MilestoneDTO milestoneDTO = mapper.map(milestone, MilestoneDTO.class); milestoneDTO.setWritable(changeManager.isMilestoneWritable(milestone)); milestoneDTO.setNumberOfRequests(changeManager.getNumberOfRequestByMilestone(milestone.getWorkspaceId(), milestone.getId())); milestoneDTO.setNumberOfOrders(changeManager.getNumberOfOrderByMilestone(milestone.getWorkspaceId(), milestone.getId())); milestoneDTOs.add(milestoneDTO); } return Response.ok(new GenericEntity<List<MilestoneDTO>>((List<MilestoneDTO>) milestoneDTOs) { }).build(); }
@GET @ApiOperation(value = "Get requests for the given milestone", response = ChangeRequestDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeRequestDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/requests") public Response getRequestsByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException { List<ChangeRequest> changeRequests = changeManager.getChangeRequestsByMilestone(workspaceId, milestoneId); List<ChangeRequestDTO> changeRequestDTOs = new ArrayList<>(); for (ChangeRequest changeRequest : changeRequests) { changeRequestDTOs.add(mapper.map(changeRequest, ChangeRequestDTO.class)); } return Response.ok(new GenericEntity<List<ChangeRequestDTO>>((List<ChangeRequestDTO>) changeRequestDTOs) { }).build(); }
@GET @ApiOperation(value = "Get orders for the given milestone", response = ChangeOrderDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of created ChangeOrderDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) @Path("{milestoneId}/orders") public Response getOrdersByMilestone( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId, @ApiParam(required = true, value = "Milestone id") @PathParam("milestoneId") int milestoneId) throws EntityNotFoundException, UserNotActiveException, AccessRightException { List<ChangeOrder> changeOrders = changeManager.getChangeOrdersByMilestone(workspaceId, milestoneId); List<ChangeOrderDTO> changeOrderDTOs = new ArrayList<>(); for (ChangeOrder changeOrder : changeOrders) { changeOrderDTOs.add(mapper.map(changeOrder, ChangeOrderDTO.class)); } return Response.ok(new GenericEntity<List<ChangeOrderDTO>>((List<ChangeOrderDTO>) changeOrderDTOs) { }).build(); }
@GET @ApiOperation(value = "Get requests for given parameters", response = ChangeRequestDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ChangeRequestDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getRequests( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { List<ChangeRequest> changeRequests = changeManager.getChangeRequests(workspaceId); List<ChangeRequestDTO> changeRequestDTOs = new ArrayList<>(); for (ChangeRequest request : changeRequests) { ChangeRequestDTO changeRequestDTO = mapper.map(request, ChangeRequestDTO.class); changeRequestDTO.setWritable(changeManager.isChangeItemWritable(request)); changeRequestDTOs.add(changeRequestDTO); } return Response.ok(new GenericEntity<List<ChangeRequestDTO>>((List<ChangeRequestDTO>) changeRequestDTOs) { }).build(); }
/** * Get all document baselines of a specific workspace * * @param workspaceId The id of the specific workspace * @return The list of baselines */ @GET @ApiOperation(value = "Get baselines", response = DocumentBaselineDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of checked out DocumentBaselineDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getDocumentBaselines( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { List<DocumentBaseline> documentBaselines = documentBaselineService.getBaselines(workspaceId); List<DocumentBaselineDTO> baselinesDTO = new ArrayList<>(); for (DocumentBaseline documentBaseline : documentBaselines) { DocumentBaselineDTO documentBaselineDTO = mapper.map(documentBaseline, DocumentBaselineDTO.class); baselinesDTO.add(documentBaselineDTO); } return Response.ok(new GenericEntity<List<DocumentBaselineDTO>>((List<DocumentBaselineDTO>) baselinesDTO) { }).build(); }
@GET @ApiOperation(value = "Get detailed workspace list for authenticated user", response = WorkspaceDetailsDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceDetailsDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/more") @Produces(MediaType.APPLICATION_JSON) public Response getDetailedWorkspacesForConnectedUser() throws EntityNotFoundException { List<WorkspaceDetailsDTO> workspaceListDTO = new ArrayList<>(); for (Workspace workspace : userManager.getWorkspacesWhereCallerIsActive()) { workspaceListDTO.add(mapper.map(workspace, WorkspaceDetailsDTO.class)); } return Response.ok(new GenericEntity<List<WorkspaceDetailsDTO>>((List<WorkspaceDetailsDTO>) workspaceListDTO) { }).build(); }
@GET @ApiOperation(value = "Get issues for given parameters", response = ChangeIssueDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ChangeIssueDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getIssues( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { List<ChangeIssue> changeIssues = changeManager.getChangeIssues(workspaceId); List<ChangeIssueDTO> changeIssueDTOs = new ArrayList<>(); for (ChangeIssue issue : changeIssues) { ChangeIssueDTO changeIssueDTO = mapper.map(issue, ChangeIssueDTO.class); changeIssueDTO.setWritable(changeManager.isChangeItemWritable(issue)); changeIssueDTOs.add(changeIssueDTO); } return Response.ok(new GenericEntity<List<ChangeIssueDTO>>((List<ChangeIssueDTO>) changeIssueDTOs) { }).build(); }
@GET @ApiOperation(value = "Get a list of ListOfValues for given parameters", response = ListOfValuesDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ListOfValuesDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getLOVs( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, WorkspaceNotEnabledException { List<ListOfValuesDTO> LOVDTOs = new ArrayList<>(); List<ListOfValues> LOVs = lovManager.findLOVFromWorkspace(workspaceId); for (ListOfValues lov : LOVs) { ListOfValuesDTO lovDTO = mapper.map(lov, ListOfValuesDTO.class); lovDTO.setDeletable(lovManager.isLOVDeletable(new ListOfValuesKey(lov.getWorkspaceId(), lov.getName()))); LOVDTOs.add(lovDTO); } return Response.ok(new GenericEntity<List<ListOfValuesDTO>>((List<ListOfValuesDTO>) LOVDTOs) { }).build(); }
@GET @ApiOperation(value = "Get baselines where part revision is involved", response = ProductBaselineDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of ProductBaselineDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("/baselines") @Produces(MediaType.APPLICATION_JSON) public Response getBaselinesWherePartRevisionHasIterations( @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) throws UserNotFoundException, WorkspaceNotFoundException, UserNotActiveException, PartRevisionNotFoundException, WorkspaceNotEnabledException { List<ProductBaseline> baselines = productService.findBaselinesWherePartRevisionHasIterations(new PartRevisionKey(workspaceId, partNumber, partVersion)); List<ProductBaselineDTO> productBaselineDTOs = new ArrayList<>(); for (ProductBaseline baseline : baselines) { productBaselineDTOs.add(mapper.map(baseline, ProductBaselineDTO.class)); } return Response.ok(new GenericEntity<List<ProductBaselineDTO>>((List<ProductBaselineDTO>) productBaselineDTOs) { }).build(); }
@GET @ApiOperation(value = "Get workspace's group membership for current user", response = WorkspaceUserGroupMemberShipDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceUserGroupMemberShipDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("usergroups/me") @Produces(MediaType.APPLICATION_JSON) public Response getWorkspaceSpecificUserGroupMemberShips( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { WorkspaceUserGroupMembership[] workspaceUserGroupMemberships = userManager.getWorkspaceSpecificUserGroupMemberships(workspaceId); List<WorkspaceUserGroupMemberShipDTO> workspaceUserGroupMemberShipDTO = new ArrayList<>(); for (WorkspaceUserGroupMembership workspaceUserGroupMembership : workspaceUserGroupMemberships) { if (workspaceUserGroupMembership != null) { workspaceUserGroupMemberShipDTO.add(mapper.map(workspaceUserGroupMembership, WorkspaceUserGroupMemberShipDTO.class)); } } return Response.ok(new GenericEntity<List<WorkspaceUserGroupMemberShipDTO>>((List<WorkspaceUserGroupMemberShipDTO>) workspaceUserGroupMemberShipDTO) { }).build(); }
@GET @ApiOperation(value = "Get roles", response = RoleDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of RoleDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getRolesInWorkspace( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { Role[] roles = roleService.getRoles(workspaceId); List<RoleDTO> rolesDTO = new ArrayList<>(); for (Role role :roles) { rolesDTO.add(mapRoleToDTO(role)); } return Response.ok(new GenericEntity<List<RoleDTO>>((List<RoleDTO>) rolesDTO) { }).build(); }
@GET @ApiOperation(value = "Get roles in use", response = RoleDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of RoleDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Path("inuse") @Produces(MediaType.APPLICATION_JSON) public Response getRolesInUseInWorkspace( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws EntityNotFoundException, UserNotActiveException { Role[] roles = roleService.getRolesInUse(workspaceId); List<RoleDTO> rolesDTO = new ArrayList<>(); for (Role role :roles) { rolesDTO.add(mapRoleToDTO(role)); } return Response.ok(new GenericEntity<List<RoleDTO>>((List<RoleDTO>) rolesDTO) { }).build(); }
@GET @ApiOperation(value = "Get workspace workflow list", response = WorkspaceWorkflowDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of WorkspaceWorkflowDTOs. It can be an empty list."), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getWorkspaceWorkflowList( @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId) throws UserNotFoundException, UserNotActiveException, WorkspaceNotFoundException, WorkspaceNotEnabledException { WorkspaceWorkflow[] workspaceWorkflowList = workflowService.getWorkspaceWorkflowList(workspaceId); List<WorkspaceWorkflowDTO> workspaceWorkflowListDTO = new ArrayList<>(); for (WorkspaceWorkflow workspaceWorkflow : workspaceWorkflowList) { workspaceWorkflowListDTO.add(mapper.map(workspaceWorkflow, WorkspaceWorkflowDTO.class)); } return Response.ok(new GenericEntity<List<WorkspaceWorkflowDTO>>((List<WorkspaceWorkflowDTO>) workspaceWorkflowListDTO) { }).build(); }
@GET @Produces(MediaType.APPLICATION_JSON) public Response listAll() { LOGGER.info("List benchmarks ..."); List<BenchmarkBean> benchmarks; if (Application.isUsingDevDb()) { benchmarks = getDevDb().getBenchmarks(); } else { try { PlatformControllerClient client = PlatformControllerClientSingleton.getInstance(); if (client == null) { throw new GUIBackendException("Couldn't connect to platform controller."); } benchmarks = client.requestBenchmarks(); } catch (Exception ex) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(InfoBean.withMessage(ex.getMessage())).build(); } } return Response.ok(new GenericEntity<List<BenchmarkBean>>(benchmarks){}).build(); }
@Path("get-backups") @GET @Produces(MediaType.APPLICATION_JSON) public Response getAvailableBackups() throws Exception { Collection<BackupMetaData> backups = context.getExhibitor().getBackupManager().getAvailableBackups(); Collection<NameAndModifiedDate> transformed = Collections2.transform ( backups, new Function<BackupMetaData, NameAndModifiedDate>() { @Override public NameAndModifiedDate apply(BackupMetaData backup) { return new NameAndModifiedDate(backup.getName(), backup.getModifiedDate()); } } ); ArrayList<NameAndModifiedDate> cleaned = Lists.newArrayList(transformed);// move out of Google's TransformingRandomAccessList GenericEntity<Collection<NameAndModifiedDate>> entity = new GenericEntity<Collection<NameAndModifiedDate>>(cleaned){}; return Response.ok(entity).build(); }
@Path("tabs") @GET @Produces(MediaType.APPLICATION_JSON) public Response getAdditionalTabSpecs() { final AtomicInteger index = new AtomicInteger(0); List<UITabSpec> names = Lists.transform ( tabs, new Function<UITab, UITabSpec>() { @Override public UITabSpec apply(UITab tab) { String base = tab.contentIsHtml() ? HTML_UI_TAB_BASE_URL : TEXT_UI_TAB_BASE_URL; return new UITabSpec(tab.getName(), base + index.getAndIncrement(), tab.contentIsHtml(), tab.getUITabType()); } } ); names = Lists.newArrayList(names); // move out of Google's TransformingRandomAccessList GenericEntity<List<UITabSpec>> entity = new GenericEntity<List<UITabSpec>>(names){}; return Response.ok(entity).build(); }
@Override protected Response convert(final E exception, final String id) { final Response.ResponseBuilder builder = Response.status(getStatus(exception)); final List<ValidationErrorXO> errors = getValidationErrors(exception); if (errors != null && !errors.isEmpty()) { final Variant variant = getRequest().selectVariant(variants); if (variant != null) { builder.type(variant.getMediaType()) .entity( new GenericEntity<List<ValidationErrorXO>>(errors) { @Override public String toString() { return getEntity().toString(); } } ); } } return builder.build(); }
@GET @Path(RestConstant.PATH_TASKS) @Produces(MediaType.APPLICATION_JSON) public Response getMyTasks(@Context HttpHeaders headers) { try { String username = headers.getHeaderString(RestConstant.HEADER_USERNAME); String locale = headers.getHeaderString(RestConstant.HEADER_LOCALE); if (username != null) { AccessAPI accessAPI = AccessAPI.get(null, null); User user = accessAPI.getUserByUserName(username); RestAPI restAPI = RestAPI.get(user, null); List<MobileTask> tasks = restAPI.getMyTasksToDo(new Locale(locale)); GenericEntity<List<MobileTask>> list = new GenericEntity<List<MobileTask>>(tasks) { }; return Response.ok(list).build(); } else { return Response.status(Response.Status.FORBIDDEN).build(); } } catch (RuntimeException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(ex.getMessage()).build(); } }
@Override public Response getAllCustomers( int page, int size, UriInfo uriInfo ) { List<Customer> customers = null; ResponseBuilder responseBuilder = Response.status( Status.OK ); String baseUri = uriInfo.getAbsolutePath( ).toString( ); // If page is 0 (absent) then get all customers if( page == 0 ) { customers = dao.findAll( ); } else { customers = dao.filterByRange( page, size ); responseBuilder.header( "Link", Util.buildFilterLinks( baseUri, page, size ) ); } for( Customer c: customers ) { c.setLink( Util.buildSelfLink( baseUri, c.getId( ) ) ); } GenericEntity<List<Customer>> entities = new GenericEntity<List<Customer>>( customers ) { }; return responseBuilder.entity( entities ).build( ); }
@Override public Response getAllOrders( int page, int size, UriInfo uriInfo ) { List<Order> orders = null; ResponseBuilder responseBuilder = Response.status( Status.OK ); String baseUri = uriInfo.getAbsolutePath( ).toString( ); // If page is 0 (absent) then get all products if( page == 0 ) { orders = dao.findAll( ); } else { orders = dao.filterByRange( page, size ); responseBuilder.header( "Link", Util.buildFilterLinks( baseUri, page, size ) ); } for( Order o: orders ) { o.setLink( Util.buildSelfLink( baseUri, o.getId( ) ) ); } GenericEntity<List<Order>> entities = new GenericEntity<List<Order>>( orders ) { }; return responseBuilder.entity( entities ).build( ); }
@Override public Response getAllProducts( int page, int size, UriInfo uriInfo ) { List<Product> products = null; ResponseBuilder responseBuilder = Response.status( Status.OK ); String baseUri = uriInfo.getAbsolutePath( ).toString( ); // If page is 0 (absent) then get all products if( page == 0 ) { products = dao.findAll( ); } else { products = dao.filterByRange( page, size ); responseBuilder.header( "Link", Util.buildFilterLinks( baseUri, page, size ) ); } for( Product p: products ) { p.setLink( Util.buildSelfLink( baseUri, p.getId( ) ) ); } GenericEntity<List<Product>> entities = new GenericEntity<List<Product>>( products ) { }; return responseBuilder.entity( entities ).build( ); }
@Test(enabled = false) public void shouldLoadObwodowaShortList() throws Exception { // given int userId = 1234; String login = "login"; String token = "token1234"; List<KomisjaShortDto> expectedResult = new ArrayList<>(); GenericEntity<List<KomisjaShortDto>> result = new GenericEntity<List<KomisjaShortDto>>(expectedResult) { }; when(userServiceEjb.loadObwodowaShortList(anyInt(), anyString(), anyString())) .thenReturn(GResultDto.validResult(OK_200, result)); // when Response response = target(format("user/%s/obwodowa", userId)).request() .header(OPW_HEADER_LOGIN, login) .header(OPW_HEADER_TOKEN, token) .get(); // then assertEquals(response.getStatus(), OK_200); assertNotNull(response.getEntity()); assertTrue(deepEquals(expectedResult, response.readEntity(new GenericType<List<KomisjaShortDto>>() { }))); }
@POST @Path("/login") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response login (Map<String, Object> obj) { String sessId = IdentityManagement.login(SecurityFactory.getSecCtx((String)obj.get(Constants.APPLICATION)), (String)obj.get(Constants.USERNAME), (String)obj.get(Constants.PASSWORD)); Map<String, Object> ret = new HashMap <String, Object> (); ret.put(Constants.LOGINSESSIONID, sessId); ret.put(Constants.STATUS, true); if (null == sessId) { ret.put(Constants.STATUS, false); } GenericEntity< Map<String, Object> > entity = new GenericEntity< Map<String, Object> > ( ret ) { }; return Response.ok().entity(entity).build(); }
final ResponseBuilder newResponseBuilder(final Status status, @Nullable final Object entity, @Nullable final GenericType<?> type) { Preconditions.checkState(this.context.variant != null); final ResponseBuilder builder = Response.status(status); if (entity != null) { builder.entity(type == null ? entity : new GenericEntity<Object>(entity, type .getType())); builder.variant(this.context.variant); final CacheControl cacheControl = new CacheControl(); cacheControl.setNoStore(true); if ("GET".equalsIgnoreCase(this.request.getMethod()) || "HEAD".equalsIgnoreCase(this.request.getMethod())) { builder.lastModified(this.context.lastModified); builder.tag(this.context.etag); if (isCachingEnabled()) { cacheControl.setNoStore(false); cacheControl.setMaxAge(0); // always stale, must revalidate each time cacheControl.setMustRevalidate(true); cacheControl.setPrivate(getUsername() != null); cacheControl.setNoTransform(true); } } builder.cacheControl(cacheControl); } return builder; }
public GResultDto<GenericEntity<List<KomisjaShortDto>>> loadObwodowaShortList(int userId, String login, String token) { if (!securityHandler.checkUser(userId, login, token)) { return GResultDto.invalidResult(UNAUTHORIZED.getStatusCode()); } OpwUser user = userBean.findUser(userId); logger.trace("userId {} user {} obwodowa {} wynik {} ", user.getId(), user.getEmail(), user.getOpwObwodowaKomisjaList().size(), user.getOpwWynikList().size()); List<KomisjaShortDto> resultList = new ArrayList<>(); for (OpwObwodowaKomisja obwodowa : user.getOpwObwodowaKomisjaList()) { int countWynik = wynikBean.countWynik(obwodowa); KomisjaShortDto komisja = new KomisjaShortDto(obwodowa.getId(), obwodowa.getPkwId(), obwodowa.getName(), obwodowa.getAddress(), countWynik); logger.trace(komisja.toString()); resultList.add(komisja); } GenericEntity<List<KomisjaShortDto>> result = new GenericEntity<List<KomisjaShortDto>>(resultList) { }; return GResultDto.validResult(OK.getStatusCode(), result); }
@GET @Path("/{id}/users") @ApiOperation(value = "Fetch all Organisations users", notes = "Displays all users of the organisation present in the database with their details", response = ServerResponse.class) @ApiResponses({ @ApiResponse(code = 401, message = "InValid organisationId or Not Allowed to Access"), @ApiResponse(code = 200, message = "OK") }) public Response getUsersForOrganisation(@Context HttpServletRequest hh, @ApiParam(value = "users' OrganisationId of the users to fetch", required = true) @PathParam("id") String organisationId) { String userId = hh.getAttribute(AppConstants.USER_ID_KEY).toString(); List<User> users = RepositoryFactory.getInstance().getUserRepository().findByOrganisationIdAndIsDeleted(organisationId, false); if ( users.isEmpty()) return Response.noContent().build(); GenericEntity<List<UserBean>> entity = new GenericEntity<List<UserBean>>(UserBean.getBeans(users)) { }; return Response.status(200).entity(entity).build(); }
@ApiOperation(value = "Get dataset file/dir listing", notes = "Returns metadata of " + "the files and folders in the dataset root.") @GET @Path("/{dsName}/files") @Produces(MediaType.APPLICATION_JSON) @AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER}) public Response getDatasetRoot(@PathParam("dsName") String name, @Context SecurityContext sc) throws AppException { Dataset dataset = getDataset(name); DatasetPath path = new DatasetPath(dataset, "/"); String fullPath = pathValidator.getFullPath(path).toString(); Inode inode = pathValidator.exists(path, inodes, true); GenericEntity<List<InodeView>> entity = getDirHelper(inode, fullPath, dataset.isShared()); return Response.ok(entity, MediaType.APPLICATION_JSON_TYPE).build(); }
private GenericEntity<List<InodeView>> getDirHelper(Inode inode, String path, boolean isShared){ List<Inode> cwdChildren = inodes.getChildren(inode); List<InodeView> kids = new ArrayList<>(); for (Inode i : cwdChildren) { InodeView inodeView = new InodeView(i, path + "/" + i.getInodePK().getName()); if (isShared) { //Get project of project__user the inode is owned by inodeView.setOwningProjectName(hdfsUsersBean.getProjectName(i.getHdfsUser().getName())); } inodeView.setUnzippingState(settings.getUnzippingState(path + "/" + i.getInodePK().getName())); Users user = userFacade.findByUsername(inodeView.getOwner()); if (user != null) { inodeView.setOwner(user.getFname() + " " + user.getLname()); inodeView.setEmail(user.getEmail()); } kids.add(inodeView); } return new GenericEntity<List<InodeView>>(kids) { }; }
@ApiOperation("Get a list of users in the cluster") @GET @Produces(MediaType.APPLICATION_JSON) @AllowedProjectRoles({AllowedProjectRoles.ANYONE}) public Response findAll(@Context SecurityContext sc) { List<Users> users = userBean.findAllUsers(); List<UserView> userViews = new ArrayList<>(); for (Users user : users) { UserView userView = new UserView(user); userViews.add(userView); } GenericEntity<List<UserView>> result = new GenericEntity<List<UserView>>(userViews) {}; return Response.ok(result, MediaType.APPLICATION_JSON_TYPE).build(); }
@Test(enabled = false) public void shouldLoadWynik() throws Exception { // given String pkwId = "1212-1"; String login = "admin"; String token = "token"; List<WynikShortDto> expectedWynikList = new ArrayList<>(0); GenericEntity<List<WynikShortDto>> expectedWynik = new GenericEntity<List<WynikShortDto>>(expectedWynikList) { }; when(komisjaServiceEjb.loadWynik(anyString(), anyString(), anyString())) .thenReturn(GResultDto.validResult(OK.getStatusCode(), expectedWynik)); // when Response response = target(format("komisja/%s/protokol", pkwId)).request() .header(OPW_HEADER_LOGIN, login) .header(OPW_HEADER_TOKEN, token) .get(); // then assertEquals(response.getStatus(), OK_200); assertNotNull(response.getEntity()); assertTrue(deepEquals(expectedWynikList, response.readEntity(new GenericType<List<WynikShortDto>>() { }))); }
@GET @Path("{id}/multiplicators") @Produces(MediaType.APPLICATION_JSON) @AllowedProjectRoles({AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER}) public Response getCurrentMultiplicator( @PathParam("id") Integer id, @Context SecurityContext sc, @Context HttpServletRequest req) throws AppException { List<YarnPriceMultiplicator> multiplicatorsList = projectController.getYarnMultiplicators(); GenericEntity<List<YarnPriceMultiplicator>> multiplicators = new GenericEntity<List<YarnPriceMultiplicator>>( multiplicatorsList) { }; return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(multiplicators).build(); }