Search in sources :

Example 6 with Location

use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.

the class LocationResourceIntTest method createEntity.

/**
 * Create an entity for this test.
 *
 * This is a static method, as tests for other entities might also need it,
 * if they test an entity which requires the current entity.
 */
public static Location createEntity(EntityManager em) {
    Location location = new Location().typeKey(DEFAULT_TYPE_KEY).countryKey(DEFAULT_COUNTRY_KEY).longitude(DEFAULT_LONGITUDE).latitude(DEFAULT_LATITUDE).name(DEFAULT_NAME).addressLine1(DEFAULT_ADDRESS_LINE_1).addressLine2(DEFAULT_ADDRESS_LINE_2).city(DEFAULT_CITY).region(DEFAULT_REGION).zip(DEFAULT_ZIP);
    // Add required entity
    XmEntity xmEntity = XmEntityResourceIntTest.createEntity(em);
    em.persist(xmEntity);
    em.flush();
    location.setXmEntity(xmEntity);
    return location;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Location(com.icthh.xm.ms.entity.domain.Location)

Example 7 with Location

use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.

the class LocationResourceIntTest method updateLocation.

@Test
@Transactional
public void updateLocation() throws Exception {
    // Initialize the database
    locationRepository.saveAndFlush(location);
    locationSearchRepository.save(location);
    int databaseSizeBeforeUpdate = locationRepository.findAll().size();
    // Update the location
    Location updatedLocation = locationRepository.findOne(location.getId());
    updatedLocation.typeKey(UPDATED_TYPE_KEY).countryKey(UPDATED_COUNTRY_KEY).longitude(UPDATED_LONGITUDE).latitude(UPDATED_LATITUDE).name(UPDATED_NAME).addressLine1(UPDATED_ADDRESS_LINE_1).addressLine2(UPDATED_ADDRESS_LINE_2).city(UPDATED_CITY).region(UPDATED_REGION).zip(UPDATED_ZIP);
    restLocationMockMvc.perform(put("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedLocation))).andExpect(status().isOk());
    // Validate the Location in the database
    List<Location> locationList = locationRepository.findAll();
    assertThat(locationList).hasSize(databaseSizeBeforeUpdate);
    Location testLocation = locationList.get(locationList.size() - 1);
    assertThat(testLocation.getTypeKey()).isEqualTo(UPDATED_TYPE_KEY);
    assertThat(testLocation.getCountryKey()).isEqualTo(UPDATED_COUNTRY_KEY);
    assertThat(testLocation.getLongitude()).isEqualTo(UPDATED_LONGITUDE);
    assertThat(testLocation.getLatitude()).isEqualTo(UPDATED_LATITUDE);
    assertThat(testLocation.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testLocation.getAddressLine1()).isEqualTo(UPDATED_ADDRESS_LINE_1);
    assertThat(testLocation.getAddressLine2()).isEqualTo(UPDATED_ADDRESS_LINE_2);
    assertThat(testLocation.getCity()).isEqualTo(UPDATED_CITY);
    assertThat(testLocation.getRegion()).isEqualTo(UPDATED_REGION);
    assertThat(testLocation.getZip()).isEqualTo(UPDATED_ZIP);
    // Validate the Location in Elasticsearch
    Location locationEs = locationSearchRepository.findOne(testLocation.getId());
    assertThat(locationEs).isEqualToComparingFieldByField(testLocation);
}
Also used : Location(com.icthh.xm.ms.entity.domain.Location) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Location

use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.

the class XmEntityGeneratorServiceIntTest method generateXmEntityWithLocations.

@Test
@SneakyThrows
public void generateXmEntityWithLocations() {
    XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
    log.info(new ObjectMapper().writeValueAsString(generatedEntity));
    Set<Location> locations = generatedEntity.getLocations();
    assertFalse("No locations generated", isEmpty(locations));
    TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
    List<LocationSpec> locationSpecs = specType.getLocations();
    Set<String> locationSpecKeys = locationSpecs.stream().map(LocationSpec::getKey).collect(toSet());
    Set<String> locationKeys = locations.stream().map(Location::getTypeKey).collect(toSet());
    assertTrue("Tag type not from locations specification", locationSpecKeys.containsAll(locationKeys));
    for (val location : locations) {
        assertFalse("Name of location is empty", isBlank(location.getName()));
        assertFalse("Coordinates and address is empty", isBlank(location.getAddressLine1()) && (location.getLatitude() == null || location.getLongitude() == null));
    }
}
Also used : lombok.val(lombok.val) LocationSpec(com.icthh.xm.ms.entity.domain.spec.LocationSpec) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Location(com.icthh.xm.ms.entity.domain.Location) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 9 with Location

use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.

the class DeleteEntityTest method createXmEntity.

private XmEntity createXmEntity() {
    XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
    xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
    return xmEntity;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Event(com.icthh.xm.ms.entity.domain.Event) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Location(com.icthh.xm.ms.entity.domain.Location)

Example 10 with Location

use of com.icthh.xm.ms.entity.domain.Location in project xm-ms-entity by xm-online.

the class LocationResource method updateLocation.

/**
 * PUT  /locations : Updates an existing location.
 *
 * @param location the location to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated location,
 * or with status 400 (Bad Request) if the location is not valid,
 * or with status 500 (Internal Server Error) if the location couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/locations")
@Timed
@PreAuthorize("hasPermission({'id': #location.id, 'newLocation': #location}, 'location', 'LOCATION.UPDATE')")
public ResponseEntity<Location> updateLocation(@Valid @RequestBody Location location) throws URISyntaxException {
    if (location.getId() == null) {
        // in order to call method with permissions check
        return this.locationResource.createLocation(location);
    }
    Location result = locationRepository.save(location);
    locationSearchRepository.save(result);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, location.getId().toString())).body(result);
}
Also used : Location(com.icthh.xm.ms.entity.domain.Location) Timed(com.codahale.metrics.annotation.Timed) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Location (com.icthh.xm.ms.entity.domain.Location)12 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)6 Tag (com.icthh.xm.ms.entity.domain.Tag)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Attachment (com.icthh.xm.ms.entity.domain.Attachment)3 Timed (com.codahale.metrics.annotation.Timed)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)2 Comment (com.icthh.xm.ms.entity.domain.Comment)2 Rating (com.icthh.xm.ms.entity.domain.Rating)2 Vote (com.icthh.xm.ms.entity.domain.Vote)2 LocationSpec (com.icthh.xm.ms.entity.domain.spec.LocationSpec)2 TypeSpec (com.icthh.xm.ms.entity.domain.spec.TypeSpec)2 SneakyThrows (lombok.SneakyThrows)2 lombok.val (lombok.val)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollectionType (com.fasterxml.jackson.databind.type.CollectionType)1 ImmutableList (com.google.common.collect.ImmutableList)1