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;
}
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();
}
Aggregations