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 toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()).append('['); if (categories != null) { sb.append("categories(").append(categories.size()).append(")"); for (RESTBackupCategory cat : categories) { sb.append('{').append(cat.getName()); for (RESTBackupResource res : cat.getResources()) { sb.append('[').append(res.getResource().getName()).append(']'); } sb.append('}'); } } sb.append(']'); return sb.toString(); }
public RESTResource createRESTResource() { RESTCategory cat = new RESTCategory(); cat.setName(getCategoryName()); RESTResource resource = new RESTResource(); resource.setCategory(cat); resource.setAttribute(createShortAttributeList()); return resource; }
/** * Inserts a feedback resource */ public void insertFeedback(Map<String, String> attributes, String data) { UNREDDFeedback feedback = new UNREDDFeedback(); feedback.setAttributes(attributes); RESTResource resource = feedback.createRESTResource(); resource.setData(data); resource.setName(String.valueOf(resource.hashCode())); client.insert(resource); }
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; }
if (resource == null) throw new BadRequestWebEx("Resource is null"); resource.setId(id); throw new NotFoundWebEx("Resource not found"); if (resource.getCategory() != null) { RESTCategory newrc = resource.getCategory(); Category oldrc = old.getCategory(); if ((newrc.getId() != null && !newrc.getId().equals(oldrc.getId())) if (resource.getDescription() != null) old.setDescription(resource.getDescription()); if (resource.getName() != null) old.setName(resource.getName()); if (resource.getMetadata() != null) old.setMetadata(resource.getMetadata()); if (resource.getAttribute() == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Attribute list is null: no change in the attrib list"); } else { if (LOGGER.isDebugEnabled()) LOGGER.debug("Attribute list is " + resource.getAttribute().size()); List<Attribute> attributes = Convert.convertAttributeList(resource .getAttribute()); resourceService.updateAttributes(id, attributes);
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 } }
if (resource == null) throw new BadRequestWebEx("Resource is null"); if (resource.getId() != null) throw new BadRequestWebEx("Id should be null"); if (resource.getCategory() == null) throw new BadRequestWebEx("Category should be not null");