Search in sources :

Example 1 with NewAdminLevel

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();
}
Also used : NewAdminEntity(org.activityinfo.server.endpoint.rest.model.NewAdminEntity) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel) NewAdminLevel(org.activityinfo.server.endpoint.rest.model.NewAdminLevel) NewAdminEntity(org.activityinfo.server.endpoint.rest.model.NewAdminEntity) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) Timed(org.activityinfo.server.util.monitoring.Timed)

Example 2 with NewAdminLevel

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();
}
Also used : NewAdminEntity(org.activityinfo.server.endpoint.rest.model.NewAdminEntity) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel) NewAdminLevel(org.activityinfo.server.endpoint.rest.model.NewAdminLevel) NewAdminEntity(org.activityinfo.server.endpoint.rest.model.NewAdminEntity) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType)

Aggregations

AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)2 AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)2 LocationType (org.activityinfo.server.database.hibernate.entity.LocationType)2 NewAdminEntity (org.activityinfo.server.endpoint.rest.model.NewAdminEntity)2 NewAdminLevel (org.activityinfo.server.endpoint.rest.model.NewAdminLevel)2 Timed (org.activityinfo.server.util.monitoring.Timed)1