private RESTBackupCategory createCategory(Category category) throws BadRequestServiceEx, InternalErrorServiceEx { LOGGER.info("Packing category " + category.getName()); RESTBackupCategory ret = new RESTBackupCategory(); ret.setName(category.getName()); SearchFilter filter = new CategoryFilter(category.getName(), SearchOperator.EQUAL_TO); List<Resource> resList = resourceService.getResourcesFull(filter, null); for (Resource resource : resList) { RESTBackupResource rbe = createResource(resource); ret.addResource(rbe); } return ret; }
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 }
@Override public long insert(Category category) throws BadRequestServiceEx, NotFoundServiceEx { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Persisting Category ... "); } if (category == null) { throw new BadRequestServiceEx("Category type must be specified !"); } Category cat = new Category(); cat.setName(category.getName()); categoryDAO.persist(cat); // // // // Persisting SecurityRule // // // List<SecurityRule> rules = category.getSecurity(); // // if (rules != null) { // for (SecurityRule rule : rules) { // rule.setCategory(cat); // securityDAO.persist(rule); // } // } return cat.getId(); }
private void quickRestoreCategory(RESTBackupCategory rbc) throws BadRequestServiceEx, NotFoundServiceEx, DuplicatedResourceNameServiceEx { LOGGER.info("Restoring category: " + rbc.getName()); Category cat = rbc2cat(rbc); long catId = categoryService.insert(cat); // TODO: cat auth for (RESTBackupResource rbr : rbc.getResources()) { if (LOGGER.isInfoEnabled()) { int attnum = (rbr != null && rbr.getResource() != null && rbr.getResource() .getAttribute() != null) ? rbr.getResource().getAttribute().size() : -1; LOGGER.info("Restoring resource: " + cat.getName() + ":" + rbr.getResource().getName() + " (" + attnum + " attrs)"); } Resource res = rbr2res(rbr, catId); resourceService.insert(res); // TODO: res auth } }
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; }
Category oldrc = old.getCategory(); if ((newrc.getId() != null && !newrc.getId().equals(oldrc.getId())) || (newrc.getName() != null && !newrc.getName().equals(oldrc.getName()))) { LOGGER.info("Trying to change category old(" + oldrc.getId() + ":" + oldrc.getName() + ") new(" + newrc.getId() + ":" + newrc.getName() + ")"); throw new BadRequestWebEx("Can't change resource category");