Search in sources :

Example 1 with AdminLevel

use of org.activityinfo.server.database.hibernate.entity.AdminLevel in project activityinfo by bedatadriven.

the class AdminLevelResource method deleteLevel.

@DELETE
public Response deleteLevel(@InjectParam EntityManager em, @InjectParam AuthenticatedUser user) {
    assertAuthorized(user);
    em.getTransaction().begin();
    AdminLevel level = em.merge(this.level);
    level.setDeleted(true);
    em.getTransaction().commit();
    return Response.ok().build();
}
Also used : AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel) NewAdminLevel(org.activityinfo.server.endpoint.rest.model.NewAdminLevel)

Example 2 with AdminLevel

use of org.activityinfo.server.database.hibernate.entity.AdminLevel 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 3 with AdminLevel

use of org.activityinfo.server.database.hibernate.entity.AdminLevel 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)

Example 4 with AdminLevel

use of org.activityinfo.server.database.hibernate.entity.AdminLevel in project activityinfo by bedatadriven.

the class AdminUpdateBuilder method build.

@Override
public SyncRegionUpdate build(User user, GetSyncRegionUpdates request) throws IOException {
    SyncRegionUpdate update = new SyncRegionUpdate();
    batch = new SqliteBatchBuilder();
    AdminLevel level = em.find(AdminLevel.class, request.getRegionId());
    JpaBatchBuilder builder = new JpaBatchBuilder(batch, em);
    if (request.getLocalVersionNumber() < LAST_VERSION_NUMBER) {
        /*
             * This level is out of date, delete all on the client and send all
             * from the server
             */
        builder.insert(Country.class, "CountryId=" + level.getCountry().getId());
        builder.insert(AdminLevel.class, "AdminLevelId=" + level.getId());
        builder.delete(AdminEntity.class, "AdminLevelId=" + level.getId());
        builder.insert(AdminEntity.class, "AdminLevelId=" + level.getId());
        update.setSql(batch.build());
    }
    update.setComplete(true);
    update.setVersion(Integer.toString(LAST_VERSION_NUMBER));
    return update;
}
Also used : SyncRegionUpdate(org.activityinfo.legacy.shared.command.result.SyncRegionUpdate) AdminLevel(org.activityinfo.server.database.hibernate.entity.AdminLevel)

Aggregations

AdminLevel (org.activityinfo.server.database.hibernate.entity.AdminLevel)4 NewAdminLevel (org.activityinfo.server.endpoint.rest.model.NewAdminLevel)3 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)2 LocationType (org.activityinfo.server.database.hibernate.entity.LocationType)2 NewAdminEntity (org.activityinfo.server.endpoint.rest.model.NewAdminEntity)2 SyncRegionUpdate (org.activityinfo.legacy.shared.command.result.SyncRegionUpdate)1 Timed (org.activityinfo.server.util.monitoring.Timed)1