use of org.qi4j.spi.entity.EntityState in project qi4j-sdk by Qi4j.
the class EntityResource method getEntityState.
private EntityState getEntityState(EntityStoreUnitOfWork unitOfWork) throws ResourceException {
EntityState entityState;
try {
EntityReference entityReference = EntityReference.parseEntityReference(identity);
entityState = unitOfWork.entityStateOf(entityReference);
} catch (EntityNotFoundException e) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
}
return entityState;
}
use of org.qi4j.spi.entity.EntityState in project qi4j-sdk by Qi4j.
the class ResourceValidity method checkRequest.
public void checkRequest() throws ResourceException {
// Check command rules
Date modificationDate = request.getConditions().getUnmodifiedSince();
if (modificationDate != null) {
EntityState state = spi.entityStateOf(entity);
// Cut off milliseconds
Date lastModified = new Date((state.lastModified() / 1000) * 1000);
if (lastModified.after(modificationDate)) {
throw new ResourceException(Status.CLIENT_ERROR_CONFLICT);
}
}
// Check query rules
modificationDate = request.getConditions().getModifiedSince();
if (modificationDate != null) {
EntityState state = spi.entityStateOf(entity);
// Cut off milliseconds
Date lastModified = new Date((state.lastModified() / 1000) * 1000);
if (!lastModified.after(modificationDate)) {
throw new ResourceException(Status.REDIRECTION_NOT_MODIFIED);
}
}
}
Aggregations