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(); }
@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; }
/** * @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; }
canUpdate = resourceAccessWrite(authUser, old.getId());
try { User authUser = extractAuthUser(sc); canUpdate = resourceAccessWrite(authUser, resource.getId());