use of org.activityinfo.server.endpoint.rest.model.NewAdminLevel in project activityinfo by bedatadriven.
the class AdminLevelResource method postNewLevel.
@POST
@Timed(name = "site.rest.admin.child_levels")
@Path("/childLevels")
@Consumes(MediaType.APPLICATION_JSON)
public Response postNewLevel(@InjectParam EntityManager em, @InjectParam AuthenticatedUser user, NewAdminLevel newLevel) throws ParseException {
assertAuthorized(user);
em.getTransaction().begin();
em.setFlushMode(FlushModeType.COMMIT);
AdminLevel child = new AdminLevel();
child.setCountry(level.getCountry());
child.setName(newLevel.getName());
child.setParent(level);
em.persist(child);
for (NewAdminEntity entity : newLevel.getEntities()) {
AdminEntity childEntity = new AdminEntity();
childEntity.setName(entity.getName());
childEntity.setLevel(child);
childEntity.setCode(entity.getCode());
childEntity.setBounds(entity.getBounds());
childEntity.setParent(em.getReference(AdminEntity.class, entity.getParentId()));
childEntity.setGeometry(entity.getGeometry());
child.getEntities().add(childEntity);
em.persist(childEntity);
}
// create bound location type
LocationType boundType = new LocationType();
boundType.setBoundAdminLevel(child);
boundType.setCountry(level.getCountry());
boundType.setName(child.getName());
em.persist(boundType);
em.getTransaction().commit();
return Response.ok().build();
}
use of org.activityinfo.server.endpoint.rest.model.NewAdminLevel in project activityinfo by bedatadriven.
the class CountryResource method postNewLevel.
@POST
@Path("adminLevels")
@Consumes(MediaType.APPLICATION_JSON)
public Response postNewLevel(@InjectParam AuthenticatedUser user, @InjectParam EntityManager em, NewAdminLevel newLevel) {
// assertAuthorized(user);
em.getTransaction().begin();
em.setFlushMode(FlushModeType.COMMIT);
AdminLevel level = new AdminLevel();
level.setCountry(country);
level.setName(newLevel.getName());
level.setVersion(1);
em.persist(level);
for (NewAdminEntity newEntity : newLevel.getEntities()) {
AdminEntity entity = new AdminEntity();
entity.setName(newEntity.getName());
entity.setLevel(level);
entity.setCode(newEntity.getCode());
entity.setBounds(newEntity.getBounds());
entity.setGeometry(newEntity.getGeometry());
level.getEntities().add(entity);
em.persist(entity);
}
// create bound location type
LocationType boundType = new LocationType();
boundType.setBoundAdminLevel(level);
boundType.setCountry(level.getCountry());
boundType.setName(level.getName());
em.persist(boundType);
em.getTransaction().commit();
return Response.ok().build();
}
Aggregations