Search in sources :

Example 1 with NewLocation

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

Aggregations

Date (java.util.Date)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 AdminEntity (org.activityinfo.server.database.hibernate.entity.AdminEntity)1 Location (org.activityinfo.server.database.hibernate.entity.Location)1 LocationType (org.activityinfo.server.database.hibernate.entity.LocationType)1 NewLocation (org.activityinfo.server.endpoint.rest.model.NewLocation)1 Timed (org.activityinfo.server.util.monitoring.Timed)1