use of org.activityinfo.store.hrd.entity.AnalysisEntity 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();
}
Aggregations