/** * Return the name provider registered for a given container resource. * * @param containerName * the name of the container. * @return the provider for the specified container resource. */ public final NameProvider nameProvider(Name<?> containerName) { NameProvider result = this.nameProviders.get(containerName); if(result==null) { throw new ApplicationRuntimeException("Unknown container '"+containerName+"'"); } return result; }
protected final ApplicationRuntimeException unexpectedFailure(String message, Object... args) { String result = String.format(message,args); this.logger.error(result); return new ApplicationRuntimeException(result); }
protected final ApplicationRuntimeException unexpectedFailure(final String message, final Object... args) { final String result = String.format(message,args); this.logger.error(result); return new ApplicationRuntimeException(result); }
protected final ApplicationRuntimeException unexpectedFailure(final Throwable failure, final String message, final Object... args) { final String result = String.format(message,args); this.logger.error(result.concat(". Full stacktrace follows"),failure); final String errorMessage=result; return new ApplicationRuntimeException(errorMessage,failure); }
private Name<String> nextName() { if(this.pendingNames.isEmpty()) { throw new ApplicationRuntimeException(String.format("No more %s names available for resource '%s'",tag,NameProvider.this.owner)); } return this.pendingNames.pop(); }
protected final ApplicationRuntimeException unexpectedFailure(Throwable failure, String message, Object... args) { String result = String.format(message,args); this.logger.error(result.concat(". Full stacktrace follows"),failure); String errorMessage=result; return new ApplicationRuntimeException(errorMessage,failure); }
@Override public DataSet get(ResourceSnapshot resource) throws ApplicationRuntimeException { throw new ApplicationRuntimeException("Failure"); }
@Override public DataSet query(ResourceSnapshot resource, Query query, ReadSession session) throws ApplicationRuntimeException { throw new ApplicationRuntimeException("Failure"); }
@Override public void update(ResourceSnapshot resource, DataSet content, WriteSession session) throws ApplicationRuntimeException { throw new ApplicationRuntimeException("Failure"); }
@Override public ResourceSnapshot create(ContainerSnapshot container, DataSet representation, WriteSession session) throws ApplicationRuntimeException { throw new ApplicationRuntimeException("Failure"); }
protected final <T extends Identifiable<?>> Optional<DateTime> dateTime(final DateTime result, final boolean mandatory, final String property, final T entity) { if(result!=null) { return Optional.of(result); } else if(!mandatory) { this.logger.debug("Ignored date for missing property {} of {} {} ({})",property,entity.getClass().getSimpleName().toLowerCase(),entity.getId(),entity); return Optional.absent(); } else { this.logger.warn("Could not create date for property {} of {} {} ({})",property,entity.getClass().getSimpleName().toLowerCase(),entity.getId(),entity); throw new ApplicationRuntimeException("Could not create date for property "+property+" of "+entity.getClass().getSimpleName().toLowerCase()+" "+entity); } }
@Override public void delete(ResourceSnapshot resource, WriteSession session) throws ApplicationRuntimeException { throw new ApplicationRuntimeException("Failure"); }
private ApplicationExecutionException createException(String errorMessage, Exception e) { LOGGER.error(errorMessage,e); if(e instanceof FeatureExecutionException) { return new ApplicationExecutionException(errorMessage,e.getCause()); } else if(e instanceof FeaturePostconditionException) { return new ApplicationExecutionException(errorMessage,new ApplicationRuntimeException(e.getMessage())); } throw new ApplicationContextException(errorMessage,e); }
@Override public final DataSet get(final ResourceSnapshot resource) { final K userId=getId(resource); try { return toDataSet( getEntity(this.backendController,userId), userId); } catch(final Exception e){ throw new ApplicationRuntimeException(e); } }
} catch (Exception e) { this.handler.remove(name); throw new ApplicationRuntimeException("Could not create member",e);
/** * {@inheritDoc}<br> * * Delete a person resource. */ @Override public void delete(ResourceSnapshot resource, WriteSession session) throws UnknownResourceException { DataSet dataSet = get(resource); try { logDebug(resource,"Deleting state:%n%s",dataSet); remove(resource.name()); session.delete(resource); session.saveChanges(); } catch (WriteSessionException e) { // Recover if failed add(resource.name(),dataSet); throw new ApplicationRuntimeException("Deletion failed",e); } }
/** * {@inheritDoc}<br> * * Create a new book resource. */ @Override public ResourceSnapshot create(ContainerSnapshot container, DataSet representation, WriteSession session) { NameProvider nameProvider = nameProvider(container.name()); Name<?> nextName = nameProvider.nextMemberName(); try { bookHandler().add(nextName,representation); ResourceSnapshot newMember = container.addMember(nextName); session.saveChanges(); return newMember; } catch (Exception e) { bookHandler().remove(nextName); throw new ApplicationRuntimeException("Could not create member",e); } }
/** * {@inheritDoc} <br> * * Update a person resource. */ @Override public void update(ResourceSnapshot resource, DataSet content, WriteSession session) throws InconsistentContentException, UnknownResourceException { DataSet dataSet = get(resource); logDebug(resource, "Enforcing consistency..."); enforceConsistency(resource,content,dataSet); try { logDebug(resource,"Persisting new state:%n%s",content); add(resource.name(),content); session.modify(resource); session.saveChanges(); } catch (Exception e) { // Recover if failed add(resource.name(),dataSet); logError(resource,e,"Something went wrong",e); throw new ApplicationRuntimeException("Update failed",e); } }