Search in sources :

Example 1 with AnalysisUpdate

use of org.activityinfo.model.analysis.AnalysisUpdate 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)

Example 2 with AnalysisUpdate

use of org.activityinfo.model.analysis.AnalysisUpdate in project activityinfo by bedatadriven.

the class WorkingModel method buildUpdate.

public AnalysisUpdate buildUpdate() {
    AnalysisUpdate update = new AnalysisUpdate();
    update.setId(id);
    update.setModel(model.toJson());
    update.setType(model.getTypeId());
    update.setLabel(label.get());
    update.setParentId(parentId.get());
    return update;
}
Also used : AnalysisUpdate(org.activityinfo.model.analysis.AnalysisUpdate)

Aggregations

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