Search in sources :

Example 11 with KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.

the class FormSubmissionResource method createCreateLocationCommand.

private CreateLocation createCreateLocationCommand(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
    // create the dto
    LocationDTO loc = new LocationDTO();
    loc.setId(new KeyGenerator().generateInt());
    loc.setLocationTypeId(activity.getLocationTypeId());
    loc.setName(data.getLocationname());
    loc.setLatitude(data.getLatitude());
    loc.setLongitude(data.getLongitude());
    CreateLocation cmd = new CreateLocation(loc);
    // get adminentities that contain the specified coordinates
    List<AdminEntity> adminentities = geocoder.geocode(data.getLatitude(), data.getLongitude());
    if (adminentities.isEmpty()) {
        AdminEntity adminEntity = createDebugAdminEntity();
        if (adminEntity != null) {
            adminentities.add(adminEntity);
        }
    }
    if (!adminentities.isEmpty()) {
        RpcMap map = cmd.getProperties();
        for (AdminEntity entity : adminentities) {
            map.put(AdminLevelDTO.getPropertyName(entity.getLevel().getId()), entity.getId());
        }
    }
    return cmd;
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) RpcMap(com.extjs.gxt.ui.client.data.RpcMap) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 12 with KeyGenerator

use of org.activityinfo.client.local.command.handler.KeyGenerator in project activityinfo by bedatadriven.

the class LocationsResource method postNewLocations.

@POST
@Path("/{typeId}")
public Response postNewLocations(@InjectParam EntityManager entityManager, @PathParam("typeId") int locationTypeId, List<NewLocation> locations) {
    KeyGenerator generator = new KeyGenerator();
    entityManager.getTransaction().begin();
    LocationType locationType = entityManager.getReference(LocationType.class, locationTypeId);
    for (NewLocation newLocation : locations) {
        Location location = new Location();
        location.setId(generator.generateInt());
        System.out.println(location.getId());
        location.setName(newLocation.getName());
        location.setLocationType(locationType);
        location.setX(newLocation.getLongitude());
        location.setY(newLocation.getLatitude());
        location.setTimeEdited(new Date());
        location.setAdminEntities(new HashSet<AdminEntity>());
        for (int entityId : newLocation.getAdminEntityIds()) {
            location.getAdminEntities().add(entityManager.getReference(AdminEntity.class, entityId));
        }
        entityManager.persist(location);
    }
    entityManager.getTransaction().commit();
    return Response.ok().build();
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) NewLocation(org.activityinfo.server.endpoint.rest.model.NewLocation) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationType(org.activityinfo.server.database.hibernate.entity.LocationType) Date(java.util.Date) NewLocation(org.activityinfo.server.endpoint.rest.model.NewLocation) Location(org.activityinfo.server.database.hibernate.entity.Location) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)12 LocationDTO (org.activityinfo.shared.dto.LocationDTO)6 SiteDTO (org.activityinfo.shared.dto.SiteDTO)6 CreateSite (org.activityinfo.shared.command.CreateSite)4 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)3 CreateResult (org.activityinfo.shared.command.result.CreateResult)3 GregorianCalendar (java.util.GregorianCalendar)2 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 Location (org.activityinfo.server.database.hibernate.entity.Location)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 Command (org.activityinfo.shared.command.Command)2 CreateLocation (org.activityinfo.shared.command.CreateLocation)2 MatchLocation (org.activityinfo.shared.command.MatchLocation)2 BatchResult (org.activityinfo.shared.command.result.BatchResult)2 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)2 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)2 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)2 RpcMap (com.extjs.gxt.ui.client.data.RpcMap)1 Date (java.util.Date)1 List (java.util.List)1