protected Resources<?> entitiesToResources(Iterable<Object> entities, PersistentEntityResourceAssembler assembler, Class<?> domainType) { if (!entities.iterator().hasNext()) { List<Object> content = Arrays.<Object> asList(WRAPPERS.emptyCollectionOf(domainType)); return new Resources<Object>(content, getDefaultSelfLink()); } List<Resource<Object>> resources = new ArrayList<Resource<Object>>(); for (Object obj : entities) { resources.add(obj == null ? null : assembler.toResource(obj)); } return new Resources<Resource<Object>>(resources, getDefaultSelfLink()); }
@RequestMapping(value = BASE_MAPPING, method = GET) public ResponseEntity<ResourceSupport> followPropertyReference(final RootResourceInformation repoRequest, @BackendId Serializable id, final @PathVariable String property, final PersistentEntityResourceAssembler assembler) throws Exception { HttpHeaders headers = new HttpHeaders(); Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> { if (prop.property.isCollectionLike()) { return toResources((Iterable<?>) it, assembler, prop.propertyType, Optional.empty()); } else if (prop.property.isMap()) { Map<Object, Resource<?>> resources = new HashMap<Object, Resource<?>>(); for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) it).entrySet()) { resources.put(entry.getKey(), assembler.toResource(entry.getValue())); } return new Resource<Object>(resources); } else { PersistentEntityResource resource = assembler.toResource(it); headers.set("Content-Location", resource.getId().getHref()); return resource; } }).orElseThrow(() -> new ResourceNotFoundException()); return ControllerUtils.toResponseEntity(HttpStatus.OK, headers, // doWithReferencedProperty(repoRequest, id, property, handler, HttpMethod.GET)); }
/** * <code>HEAD /{repository}/{id}</code> * * @param resourceInformation * @param id * @return * @throws HttpRequestMethodNotSupportedException * @since 2.2 */ @RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.HEAD) public ResponseEntity<?> headForItemResource(RootResourceInformation resourceInformation, @BackendId Serializable id, PersistentEntityResourceAssembler assembler) throws HttpRequestMethodNotSupportedException { return getItemResource(resourceInformation, id).map(it -> { Links links = new Links(assembler.toResource(it).getLinks()); HttpHeaders headers = headersPreparer.prepareHeaders(resourceInformation.getPersistentEntity(), it); headers.add(LINK_HEADER, links.toString()); return new ResponseEntity<Object>(headers, HttpStatus.NO_CONTENT); }).orElseThrow(() -> new ResourceNotFoundException()); }
if (propertyId.equals(accessor1.getIdentifier().toString())) { PersistentEntityResource resource1 = assembler.toResource(obj); headers.set("Content-Location", resource1.getId().getHref()); return resource1; if (propertyId.equals(accessor2.getIdentifier().toString())) { PersistentEntityResource resource2 = assembler.toResource(entry.getValue()); headers.set("Content-Location", resource2.getId().getHref()); return resource2;
/** * 데이터 소스의 상세정보를 가져옵니다. 임시 데이터 소스가 존재할 경우 */ @Transactional(readOnly = true) @RequestMapping(value = "/datasources/{dataSourceId}", method = RequestMethod.GET) public ResponseEntity<?> findDataSources(@PathVariable("dataSourceId") String dataSourceId, @RequestParam(value = "includeUnloadedField", required = false) Boolean includeUnloadedField, PersistentEntityResourceAssembler resourceAssembler) { DataSource resultDataSource = dataSourceService.findDataSourceIncludeTemporary(dataSourceId, includeUnloadedField); return ResponseEntity.ok(resourceAssembler.toResource(resultDataSource)); }
@RequestMapping(path = "/workbooks/{workbookId}/comments/{commentId}", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findCommentInWorkbook( @PathVariable("workbookId") String workbookId, @PathVariable("commentId") Long commentId, PersistentEntityResourceAssembler resourceAssembler) { Comment persistComment = validateComment(workbookId, commentId); return ResponseEntity.ok(resourceAssembler.toResource(persistComment)); }
/** * alias 상세정보를 가져옵니다. * * @param aliasId * @param resourceAssembler * @return */ @Transactional(readOnly = true) @RequestMapping(value = "/datasources/aliases/{aliasId}", method = RequestMethod.GET) public ResponseEntity<?> findDataSources(@PathVariable("aliasId") Long aliasId, PersistentEntityResourceAssembler resourceAssembler) { DataSourceAlias alias = dataSourceAliasRepository.findOne(aliasId); if (alias == null) { throw new ResourceNotFoundException(String.valueOf(aliasId)); } return ResponseEntity.ok(resourceAssembler.toResource(alias)); } }
/** * User 상세 조회 */ @RequestMapping(path = "/users/{username:.+}", method = RequestMethod.GET) public ResponseEntity<?> findDetailUser(@PathVariable("username") String username, PersistentEntityResourceAssembler resourceAssembler) { User user = userRepository.findByUsername(username); if (user == null) { return ResponseEntity.notFound().build(); } return ResponseEntity.ok(resourceAssembler.toResource(user)); }
/** * * @param resourceAssembler * @return */ @RequestMapping(path = "/workspaces/my/all", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findMyWorkspaceList(PersistentEntityResourceAssembler resourceAssembler) { String username = AuthUtils.getAuthUserName(); List<String> targets = Lists.newArrayList(username); targets.addAll(groupRepository.findGroupIdsByMemberId(username)); List<Workspace> myWorkspaces = workspaceRepository.findMyWorkspaces(username, targets); List<PersistentEntityResource> resources = myWorkspaces.stream() .map((workspace) -> resourceAssembler.toResource(workspace)) .collect(toList()); return ResponseEntity.ok(new Resources(resources)); }
@RequestMapping(path = "/dashboards/{dashboardId}/copy", method = RequestMethod.POST) public @ResponseBody ResponseEntity<?> copyDashboard(@PathVariable("dashboardId") String dashboardId, PersistentEntityResourceAssembler resourceAssembler) { DashBoard dashBoard = dashboardRepository.findOne(dashboardId); if(dashBoard == null) { throw new ResourceNotFoundException("Dashboard(" + dashboardId + ") not found"); } DashBoard copiedDashboard = dashBoardService.copy(dashBoard, dashBoard.getWorkBook(), true); return ResponseEntity.ok(resourceAssembler.toResource(copiedDashboard)); }
@RequestMapping(path = "/widgets/{widgetId}/copy", method = RequestMethod.POST) public @ResponseBody ResponseEntity<?> copyWidget(@PathVariable("widgetId") String widgetId, PersistentEntityResourceAssembler resourceAssembler) { Widget widget = widgetRepository.findOne(widgetId); if (widget == null) { throw new ResourceNotFoundException("Widget(" + widgetId + ") not found"); } Widget copiedWidget = widgetService.copy(widget, widget.getDashBoard(), true); return ResponseEntity.ok(resourceAssembler.toResource(copiedWidget)); }
@RequestMapping(path = {"/catalogs/{fromCatalogIds}/copy", "/catalogs/{fromCatalogIds}/copy/{toCatalogId}"}, method = RequestMethod.POST) public ResponseEntity<?> copyBook(@PathVariable("fromCatalogIds") String fromCatalogIds, @PathVariable("toCatalogId") Optional<String> toCatalogId, PersistentEntityResourceAssembler resourceAssembler) { Catalog fromCatalog = catalogRepository.findOne(fromCatalogIds); if (fromCatalog == null) { return ResponseEntity.notFound().build(); } Catalog copiedCatalog = catalogService.copy(fromCatalog, toCatalogId); return ResponseEntity.ok(resourceAssembler.toResource(copiedCatalog)); }
protected Resources<?> entitiesToResources(Iterable<Object> entities, PersistentEntityResourceAssembler assembler, Class<?> domainType) { if (!entities.iterator().hasNext()) { List<Object> content = Arrays.<Object> asList(WRAPPERS.emptyCollectionOf(domainType)); return new Resources<Object>(content, getDefaultSelfLink()); } List<Resource<Object>> resources = new ArrayList<Resource<Object>>(); for (Object obj : entities) { resources.add(obj == null ? null : assembler.toResource(obj)); } return new Resources<Resource<Object>>(resources, getDefaultSelfLink()); }
@RequestMapping(path = {"/books/{bookId}/copy", "/books/{bookId}/copy/{folderId}"}, method = RequestMethod.POST) public ResponseEntity<?> copyBook(@PathVariable("bookId") String bookId, @PathVariable("folderId") Optional<String> folderId, @RequestParam("toWorkspace") Optional<String> toWorkspace, PersistentEntityResourceAssembler resourceAssembler) { Book book = bookRepository.findOne(bookId); if(book == null) { return ResponseEntity.notFound().build(); } if(folderId.isPresent() && bookRepository.findOne(folderId.get()) == null) { throw new ResourceNotFoundException(folderId.get()); } if(folderId.isPresent() && Folder.ROOT.equals(folderId.get())) { folderId = Optional.empty(); } if(!(book instanceof WorkBook)) { throw new RuntimeException("Not supported book type."); } WorkBook copiedBook = bookService.copy(book, folderId, toWorkspace); return ResponseEntity.ok(resourceAssembler.toResource(copiedBook)); }
@RequestMapping(path = "/workspaces/{workspaceId}/books/{bookId}", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findBooksInWorkspace(@PathVariable("workspaceId") String workspaceId, @PathVariable("bookId") String bookId, @RequestParam(required = false) String bookType, PersistentEntityResourceAssembler resourceAssembler) { if (StringUtils.isNotEmpty(bookType) && !Book.SEARCHABLE_BOOKS.contains(bookType.toLowerCase())) { throw new IllegalArgumentException("Invalid widget type. choose " + Book.SEARCHABLE_BOOKS); } Workspace workspace = workspaceRepository.findOne(workspaceId); if (workspace == null) { return ResponseEntity.notFound().build(); } if ("ROOT".equalsIgnoreCase(bookId)) { workspace.setBookType(bookType); // 타입별 조회 위함 return ResponseEntity.ok(resourceAssembler.toResource(workspace)); } Book book = bookRepository.findOne(bookId); if (book == null) { throw new ResourceNotFoundException(bookId); } book.setBookType(bookType); // 타입별 조회 위함 return ResponseEntity.ok(resourceAssembler.toResource(book)); }
@RequestMapping(value="", method = RequestMethod.POST) public @ResponseBody PersistentEntityResource postDataset( @RequestParam(value="storageType", required=false, defaultValue="") String storageType, @RequestBody Resource<PrDataset> datasetResource, PersistentEntityResourceAssembler resourceAssembler ) { PrDataset dataset = null; PrDataset savedDataset = null; try { dataset = datasetResource.getContent(); this.datasetService.setConnectionInfo(dataset); savedDataset = datasetRepository.save(dataset); LOGGER.debug(savedDataset.toString()); this.datasetService.afterCreate(savedDataset, storageType); this.datasetRepository.flush(); } catch (Exception e) { LOGGER.error("postDataset(): caught an exception: ", e); throw PrepException.create(PrepErrorCodes.PREP_DATASET_ERROR_CODE, PrepMessageKey.MSG_DP_ALERT_DATASET_FAIL_TO_CREATE, e.getMessage()); } return resourceAssembler.toResource(savedDataset); }
@RequestMapping(value = BASE_MAPPING, method = GET) public ResponseEntity<ResourceSupport> followPropertyReference(final RootResourceInformation repoRequest, @BackendId Serializable id, final @PathVariable String property, final PersistentEntityResourceAssembler assembler) throws Exception { HttpHeaders headers = new HttpHeaders(); Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> { if (prop.property.isCollectionLike()) { return toResources((Iterable<?>) it, assembler, prop.propertyType, Optional.empty()); } else if (prop.property.isMap()) { Map<Object, Resource<?>> resources = new HashMap<Object, Resource<?>>(); for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) it).entrySet()) { resources.put(entry.getKey(), assembler.toResource(entry.getValue())); } return new Resource<Object>(resources); } else { PersistentEntityResource resource = assembler.toResource(it); headers.set("Content-Location", resource.getId().getHref()); return resource; } }).orElseThrow(() -> new ResourceNotFoundException()); return ControllerUtils.toResponseEntity(HttpStatus.OK, headers, // doWithReferencedProperty(repoRequest, id, property, handler, HttpMethod.GET)); }
@RequestMapping(value="", method = RequestMethod.POST) public @ResponseBody PersistentEntityResource postDataflow( @RequestBody Resource<PrDataflow> dataflowResource, PersistentEntityResourceAssembler resourceAssembler ) { PrDataflow dataflow = null; PrDataflow savedDataflow = null; try { dataflow = dataflowResource.getContent(); savedDataflow = dataflowRepository.save(dataflow); LOGGER.debug(savedDataflow.toString()); this.dataflowService.afterCreate(savedDataflow); this.dataflowRepository.flush(); } catch (Exception e) { LOGGER.error("postDataflow(): caught an exception: ", e); throw PrepException.create(PrepErrorCodes.PREP_DATAFLOW_ERROR_CODE, PrepMessageKey.MSG_DP_ALERT_NO_DATAFLOW, e.getMessage()); } return resourceAssembler.toResource(savedDataflow); }
/** * * @param resourceAssembler * @return */ @RequestMapping(path = "/workspaces/my", method = RequestMethod.GET) public @ResponseBody ResponseEntity<?> findMyWorkspace(PersistentEntityResourceAssembler resourceAssembler) { Workspace myWorkspace = workspaceRepository.findPrivateWorkspaceByOwnerId(AuthUtils.getAuthUserName()); if (myWorkspace == null) { myWorkspace = new Workspace(); myWorkspace.setId("GUEST_WORKSPACE"); myWorkspace.setName("Guest Workspace"); myWorkspace.setOwnerId(AuthUtils.getAuthUserName()); } return ResponseEntity.ok(resourceAssembler.toResource(myWorkspace)); }
/** * <code>HEAD /{repository}/{id}</code> * * @param resourceInformation * @param id * @return * @throws HttpRequestMethodNotSupportedException * @since 2.2 */ @RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.HEAD) public ResponseEntity<?> headForItemResource(RootResourceInformation resourceInformation, @BackendId Serializable id, PersistentEntityResourceAssembler assembler) throws HttpRequestMethodNotSupportedException { return getItemResource(resourceInformation, id).map(it -> { Links links = new Links(assembler.toResource(it).getLinks()); HttpHeaders headers = headersPreparer.prepareHeaders(resourceInformation.getPersistentEntity(), it); headers.add(LINK_HEADER, links.toString()); return new ResponseEntity<Object>(headers, HttpStatus.NO_CONTENT); }).orElseThrow(() -> new ResourceNotFoundException()); }