use of org.activityinfo.server.endpoint.rest.model.NewLocation in project activityinfo by bedatadriven.
the class LocationsResource method postNewLocations.
@POST
@Path("/{typeId}")
@Timed(name = "api.rest.locations.post")
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