private RESTResource createRESTResource(Resource resource) { RESTResource ret = new RESTResource(); ret.setCategory(new RESTCategory(resource.getCategory().getName())); ret.setName(resource.getName()); ret.setDescription(resource.getDescription()); ret.setMetadata(resource.getMetadata()); if (resource.getData() != null) ret.setData(resource.getData().getData()); if (CollectionUtils.isNotEmpty(resource.getAttribute())) ret.setAttribute(Convert.convertToShortAttributeList(resource.getAttribute())); return ret; }
@Override public String getData(SecurityContext sc, String catName, String resName) throws NotFoundWebEx, ConflictWebEx, BadRequestWebEx, InternalErrorWebEx { if (LOGGER.isDebugEnabled()) LOGGER.debug("getData(" + catName + "," + resName + ")"); if (catName == null) throw new BadRequestWebEx("Category is null"); if (resName == null) throw new BadRequestWebEx("Resource is null"); SearchFilter filter = new AndFilter(new CategoryFilter(catName, SearchOperator.EQUAL_TO), new FieldFilter(BaseField.NAME, resName, SearchOperator.EQUAL_TO)); List<Resource> resources = null; try { User user = extractAuthUser(sc); resources = resourceService.getResourcesFull(filter, user); } catch (BadRequestServiceEx ex) { throw new BadRequestWebEx(ex.getMessage()); } catch (InternalErrorServiceEx ex) { throw new InternalErrorWebEx(ex.getMessage()); } if (resources.isEmpty()) { throw new NotFoundWebEx("No resource found"); } else if (resources.size() > 1) { throw new ConflictWebEx("Too many resources match the request"); } return resources.get(0).getData().getData(); }
/** * @param list * @param includeAttributes * @param includeData * @param authUser * @return List<Resource> */ private List<Resource> configResourceList(List<Resource> list, boolean includeAttributes, boolean includeData, User authUser) { List<Resource> rList = new LinkedList<>(); for (Resource resource : list) { Resource res = new Resource(); res.setCategory(resource.getCategory()); res.setCreation(resource.getCreation()); res.setDescription(resource.getDescription()); res.setId(resource.getId()); res.setLastUpdate(resource.getLastUpdate()); res.setName(resource.getName()); if (includeData) { res.setData(resource.getData()); } if (includeAttributes) { res.setAttribute(resource.getAttribute()); } rList.add(res); } return rList; }
StoredData data = resource.getData(); if (data != null) { data.setId(r.getId());