Search in sources :

Example 1 with Location

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

the class LocationService method save.

/**
 * Save a xmEntity.
 *
 * @param location the location to save
 * @return the persisted XmEntity
 */
public Location save(Location location) {
    log.debug("Request to save location : {}", location);
    Location result = locationRepository.save(location);
    locationSearchRepository.save(location);
    return result;
}
Also used : Location(com.icthh.xm.ms.entity.domain.Location)

Example 2 with Location

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

the class LocationResource method createLocation.

/**
 * POST  /locations : Create a new location.
 *
 * @param location the location to create
 * @return the ResponseEntity with status 201 (Created) and with body the new location, or with status 400 (Bad Request) if the location has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/locations")
@Timed
@PreAuthorize("hasPermission({'location': #location}, 'LOCATION.CREATE')")
public ResponseEntity<Location> createLocation(@Valid @RequestBody Location location) throws URISyntaxException {
    if (location.getId() != null) {
        throw new BusinessException(ErrorConstants.ERR_BUSINESS_IDEXISTS, "A new location cannot already have an ID");
    }
    Location result = locationRepository.save(location);
    locationSearchRepository.save(result);
    return ResponseEntity.created(new URI("/api/locations/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BusinessException(com.icthh.xm.commons.exceptions.BusinessException) URI(java.net.URI) Location(com.icthh.xm.ms.entity.domain.Location) PostMapping(org.springframework.web.bind.annotation.PostMapping) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with Location

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

the class XmEntityResourceExtendedIntTest method createEntityComplexIncoming.

/**
 * Creates incoming Entity as from HTTP request.
 * Potentially cam be moved to DTO
 *
 * @param em - Entity manager
 * @return XmEntity for incoming request
 */
public static XmEntity createEntityComplexIncoming(EntityManager em) {
    XmEntity entity = createEntity(em);
    entity.getTags().add(new Tag().typeKey(DEFAULT_TAG_KEY).startDate(DEFAULT_START_DATE).name(DEFAULT_TAG_NAME));
    entity.getAttachments().add(new Attachment().typeKey(DEFAULT_ATTACHMENT_KEY).name(DEFAULT_ATTACHMENT_NAME).startDate(DEFAULT_ATTACHMENT_START_DATE).endDate(DEFAULT_ATTACHMENT_END_DATE).valueContentType(DEFAULT_ATTACHMENT_CONTENT_TYPE).content(new Content().value(DEFAULT_ATTACHMENT_CONTENT_VALUE.getBytes())).contentUrl(DEFAULT_ATTACHMENT_URL).description(DEFAULT_ATTACHMENT_DESCRIPTION));
    entity.getLocations().add(new Location().typeKey(DEFAULT_LOCATION_KEY).name(DEFAULT_LOCATION_NAME).countryKey(DEFAULT_LOCATION_COUNTRY_KEY));
    return entity;
}
Also used : Content(com.icthh.xm.ms.entity.domain.Content) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) Location(com.icthh.xm.ms.entity.domain.Location)

Example 4 with Location

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

the class LocationResourceIntTest method createLocation.

@Test
@Transactional
public void createLocation() throws Exception {
    int databaseSizeBeforeCreate = locationRepository.findAll().size();
    // Create the Location
    restLocationMockMvc.perform(post("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(location))).andExpect(status().isCreated());
    // Validate the Location in the database
    List<Location> locationList = locationRepository.findAll();
    assertThat(locationList).hasSize(databaseSizeBeforeCreate + 1);
    Location testLocation = locationList.get(locationList.size() - 1);
    assertThat(testLocation.getTypeKey()).isEqualTo(DEFAULT_TYPE_KEY);
    assertThat(testLocation.getCountryKey()).isEqualTo(DEFAULT_COUNTRY_KEY);
    assertThat(testLocation.getLongitude()).isEqualTo(DEFAULT_LONGITUDE);
    assertThat(testLocation.getLatitude()).isEqualTo(DEFAULT_LATITUDE);
    assertThat(testLocation.getName()).isEqualTo(DEFAULT_NAME);
    assertThat(testLocation.getAddressLine1()).isEqualTo(DEFAULT_ADDRESS_LINE_1);
    assertThat(testLocation.getAddressLine2()).isEqualTo(DEFAULT_ADDRESS_LINE_2);
    assertThat(testLocation.getCity()).isEqualTo(DEFAULT_CITY);
    assertThat(testLocation.getRegion()).isEqualTo(DEFAULT_REGION);
    assertThat(testLocation.getZip()).isEqualTo(DEFAULT_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 5 with Location

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

the class LocationResourceIntTest method equalsVerifier.

@Test
@Transactional
public void equalsVerifier() throws Exception {
    TestUtil.equalsVerifier(Location.class);
    Location location1 = new Location();
    location1.setId(1L);
    Location location2 = new Location();
    location2.setId(location1.getId());
    assertThat(location1).isEqualTo(location2);
    location2.setId(2L);
    assertThat(location1).isNotEqualTo(location2);
    location1.setId(null);
    assertThat(location1).isNotEqualTo(location2);
}
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)

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