Search in sources :

Example 1 with LoadResult

use of com.googlecode.objectify.LoadResult in project activityinfo by bedatadriven.

the class AnalysesResource method update.

@POST
public Response update(String jsonString) throws JsonMappingException {
    final AnalysisUpdate update = Json.fromJson(AnalysisUpdate.class, Json.parse(jsonString));
    assertAuthorized(update);
    // TODO: verify json
    Hrd.ofy().transact(new Runnable() {

        @Override
        public void run() {
            LoadResult<AnalysisEntity> existingEntity = Hrd.ofy().load().key(Key.create(AnalysisEntity.class, update.getId()));
            long newVersion;
            if (existingEntity.now() == null) {
                newVersion = 1;
            } else {
                newVersion = existingEntity.now().getVersion() + 1;
            }
            AnalysisEntity entity = new AnalysisEntity();
            entity.setId(update.getId());
            entity.setParentId(update.getParentId());
            entity.setType(update.getType());
            entity.setVersion(newVersion);
            entity.setLabel(update.getLabel());
            entity.setModel(update.getModel().toJson());
            AnalysisSnapshotEntity snapshot = new AnalysisSnapshotEntity();
            snapshot.setAnalysis(Key.create(entity));
            snapshot.setVersion(newVersion);
            snapshot.setType(update.getType());
            snapshot.setLabel(update.getLabel());
            snapshot.setModel(update.getModel().toJson());
            snapshot.setTime(new Date());
            snapshot.setUserId(userProvider.get().getId());
            Hrd.ofy().save().entities(entity, snapshot);
        }
    });
    return Response.status(Response.Status.OK).build();
}
Also used : AnalysisEntity(org.activityinfo.store.hrd.entity.AnalysisEntity) AnalysisUpdate(org.activityinfo.model.analysis.AnalysisUpdate) AnalysisSnapshotEntity(org.activityinfo.store.hrd.entity.AnalysisSnapshotEntity) LoadResult(com.googlecode.objectify.LoadResult) Date(java.util.Date)

Aggregations

LoadResult (com.googlecode.objectify.LoadResult)1 Date (java.util.Date)1 AnalysisUpdate (org.activityinfo.model.analysis.AnalysisUpdate)1 AnalysisEntity (org.activityinfo.store.hrd.entity.AnalysisEntity)1 AnalysisSnapshotEntity (org.activityinfo.store.hrd.entity.AnalysisSnapshotEntity)1