@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_CREATE + "')") public AnyTypeTO create(final AnyTypeTO anyTypeTO) { if (StringUtils.isBlank(anyTypeTO.getKey())) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); sce.getElements().add(AnyType.class.getSimpleName() + " key"); throw sce; } if (anyTypeDAO.find(anyTypeTO.getKey()) != null) { throw new DuplicateException(anyTypeTO.getKey()); } return binder.getAnyTypeTO(anyTypeDAO.save(binder.create(anyTypeTO))); }
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_UPDATE + "')") public AnyTypeTO update(final AnyTypeTO anyTypeTO) { AnyType anyType = anyTypeDAO.find(anyTypeTO.getKey()); if (anyType == null) { LOG.error("Could not find anyType '" + anyTypeTO.getKey() + "'"); throw new NotFoundException(anyTypeTO.getKey()); } binder.update(anyType, anyTypeTO); anyType = anyTypeDAO.save(anyType); return binder.getAnyTypeTO(anyTypeDAO.save(anyType)); }
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_READ + "')") @Transactional(readOnly = true) public AnyTypeTO read(final String key) { AnyType anyType = anyTypeDAO.find(key); if (anyType == null) { LOG.error("Could not find anyType '" + key + "'"); throw new NotFoundException(key); } return binder.getAnyTypeTO(anyType); }
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_DELETE + "')") public AnyTypeTO delete(final String key) { AnyType anyType = anyTypeDAO.find(key); if (anyType == null) { LOG.error("Could not find anyType '" + key + "'"); throw new NotFoundException(key); } Integer anyObjects = anyObjectDAO.countByType().get(anyType); if (anyObjects != null && anyObjects > 0) { LOG.error("{} AnyObject instances found for {}, aborting", anyObjects, anyType); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType); sce.getElements().add("AnyObject instances found for " + key); throw sce; } try { return binder.delete(anyType); } catch (IllegalArgumentException e) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest); sce.getElements().add(e.getMessage()); throw sce; } }
@Override protected AnyTypeTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException { String key = null; if (ArrayUtils.isNotEmpty(args)) { for (int i = 0; key == null && i < args.length; i++) { if (args[i] instanceof String) { key = (String) args[i]; } else if (args[i] instanceof AnyTypeTO) { key = ((AnyTypeTO) args[i]).getKey(); } } } if (StringUtils.isNotBlank(key)) { try { return binder.getAnyTypeTO(anyTypeDAO.find(key)); } catch (Throwable ignore) { LOG.debug("Unresolved reference", ignore); throw new UnresolvedReferenceException(ignore); } } throw new UnresolvedReferenceException(); }