/** * @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; }
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; }
private void validateResourceName(Resource resource, boolean isUpdate) throws DuplicatedResourceNameServiceEx { Resource existentResource = resourceDAO.findByName(resource.getName()); if (existentResource != null && !(isUpdate && existentResource.getId().equals(resource.getId()))) { String validResourceName = suggestValidResourceName(resource.getName()); throw new DuplicatedResourceNameServiceEx(validResourceName); } }
@Override public long update(Resource resource) throws NotFoundServiceEx, DuplicatedResourceNameServiceEx { Resource orig = resourceDAO.find(resource.getId()); if (orig == null) { throw new NotFoundServiceEx("Resource not found " + resource.getId()); } validateResourceName(resource, true); // reset some server-handled data. resource.setCreation(orig.getCreation()); resource.setLastUpdate(new Date()); resourceDAO.merge(resource); return orig.getId(); }
Category category = resource.getCategory(); if (category == null) { throw new BadRequestServiceEx("Category type must be specified"); Resource r = new Resource(); r.setCreation(new Date()); r.setDescription(resource.getDescription()); r.setMetadata(resource.getMetadata()); r.setName(resource.getName()); r.setCategory(loadedCategory); List<Attribute> attributes = resource.getAttribute(); if (attributes != null) { for (Attribute a : attributes) { StoredData data = resource.getData(); if (data != null) { data.setId(r.getId()); data.setResource(r); storedDataDAO.persist(data); List<SecurityRule> rules = resource.getSecurity(); return r.getId();
public static Resource convertResource(RESTResource resource) { Category category = new Category(); if (resource.getCategory().getName() != null) category.setName(resource.getCategory().getName()); if (resource.getCategory().getId() != null) category.setId(resource.getCategory().getId()); Resource r = new Resource(); r.setDescription(resource.getDescription()); r.setMetadata(resource.getMetadata()); r.setName(resource.getName()); r.setCategory(category); // Parsing Attributes list if (CollectionUtils.isNotEmpty(resource.getAttribute())) { List<Attribute> attributes = Convert.convertAttributeList(resource.getAttribute()); r.setAttribute(attributes); } RESTStoredData dataDto = resource.getStore(); if (dataDto != null) { StoredData data = new StoredData(); data.setData(dataDto.getData()); r.setData(data); } return r; }
Category oldrc = old.getCategory(); if ((newrc.getId() != null && !newrc.getId().equals(oldrc.getId())) || (newrc.getName() != null && !newrc.getName().equals(oldrc.getName()))) { canUpdate = resourceAccessWrite(authUser, old.getId()); old.setDescription(resource.getDescription()); if (resource.getName() != null) old.setName(resource.getName()); if (resource.getMetadata() != null) old.setMetadata(resource.getMetadata());
@Override public List<StoredData> getAllFull() { List<StoredData> found = storedDataDAO.findAll(); for (StoredData data : found) { Resource resource = data.getResource(); if (resource != null) { List<SecurityRule> security = resourceDAO.findSecurityRules(resource.getId()); resource.setSecurity(security); List<Attribute> attribute = resourceDAO.findAttributes(resource.getId()); resource.setAttribute(attribute); } } return found; }
public UNREDDResource(Resource resource) { // category sanity check if(! getCategoryName().equals(resource.getCategory().getName())) { throw new IllegalArgumentException("Bad resource category " + resource.getCategory().getName() + ": only handling " + getCategoryName()); } // copy attribs if (resource.getAttribute() != null) { // SG - when there are no attributes, resource.getAttribute() returns null - can't modify resource.getAttribute() for (Attribute a : resource.getAttribute()) { originalAttributes.put(a.getName(), a); DataType type = getAttributeMap().get(a.getName()); if(type == null) { if( ! getReverseAttributes().contains(a.getTextValue())) { LOGGER.error("Bad attribute name " + a + " for class " + this.getClass().getSimpleName()); continue; } } else if( type != a.getType()) { LOGGER.error("Bad attribute type " + a + " for class " + this.getClass().getSimpleName()); continue; } attributes.put(a.getName(), a.getValue()); } } // TODO: copy other resource info }
private Resource rbr2res(RESTBackupResource rbr, long catId) { Resource ret = Convert.convertResource(rbr.getResource()); ret.getCategory().setId(catId); // remap category return ret; }
@Override public List<Resource> findResources(List<Long> resourcesIds) { Search search = new Search(Resource.class); Filter filter = Filter.in("id", resourcesIds); search.addFilter(filter); List<Resource> resourceToSet = super.search(search); //Initialize Lazy collection for(Resource resource : resourceToSet){ if(!Hibernate.isInitialized(resource.getSecurity())){ Hibernate.initialize(resource.getSecurity()); } } return resourceToSet; }
public List<Resource> searchStatsDataByStatsDef2(String statsDefName) throws UnsupportedEncodingException, JAXBException { SearchFilter filter = createCategoryFilter(UNREDDCategories.STATSDATA); if (statsDefName != null) { filter = new AndFilter(filter, createAttributeFilter(UNREDDStatsData.Attributes.STATSDEF, statsDefName)); } List<Resource> ret = new ArrayList<Resource>(); ShortResourceList list = client.searchResources(filter); if ( CollectionUtils.isNotEmpty(list.getList())) { for (ShortResource shortResource : list.getList()) { Resource resource = client.getResource(shortResource.getId()); // TODO: use new metod getFull() String data = client.getData(shortResource.getId(), MediaType.WILDCARD_TYPE); StoredData sdata = new StoredData(); sdata.setData(data); resource.setData(sdata); ret.add(resource); } } else { LOGGER.info("No stats data found for stats def: " + statsDefName); } return ret; }
@Override public void updateAttributes(long id, List<Attribute> attributes) throws NotFoundServiceEx { Resource resource = resourceDAO.find(id); if (resource == null) { throw new NotFoundServiceEx("Resource not found " + id); } // // Removing old attributes // List<Attribute> oldList = resource.getAttribute(); if (oldList != null) { for (Attribute a : oldList) { attributeDAO.removeById(a.getId()); } } // // Saving old attributes // for (Attribute a : attributes) { a.setResource(resource); attributeDAO.persist(a); } }
private RESTBackupResource createResource(Resource resource) { LOGGER.info("Packing resource " + resource.getName()); RESTResource rr = createRESTResource(resource); RESTBackupResource rbr = new RESTBackupResource(); rbr.setResource(rr); return rbr; }
@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(); }
try { User authUser = extractAuthUser(sc); canUpdate = resourceAccessWrite(authUser, resource.getId());
SecurityRule sr = getRuleForGroup(resource.getSecurity(), group); if(sr == null){ newSR.setResource(resource); securityDAO.persist(newSR); resource.getSecurity().add(newSR);
shortResource.setCanDelete(true); } else { for (SecurityRule rule : resource.getSecurity()) { User owner = rule.getUser(); UserGroup userGroup = rule.getGroup();