Search in sources :

Example 1 with XmEntity

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

the class XmEntityTypeKeyResolver method getAppendSegments.

@Override
protected String[] getAppendSegments(SeparatorSegmentedLepKey baseKey, LepMethod method, LepManagerService managerService) {
    XmEntity xmEntity = getRequiredParam(method, "xmEntity", XmEntity.class);
    String translatedXmEntityTypeKey = translateToLepConvention(xmEntity.getTypeKey());
    return new String[] { translatedXmEntityTypeKey };
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 2 with XmEntity

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

the class SystemEventMapper method toProfile.

/**
 * Mapping system event to profile.
 * @param event the system event.
 * @param profile the user profile.
 */
public static void toProfile(SystemEvent event, Profile profile) {
    if (profile.getXmentity() == null) {
        profile.setXmentity(new XmEntity());
    }
    XmEntity entity = profile.getXmentity();
    entity.setTypeKey(Constants.ACCOUNT_TYPE_KEY);
    profile.setXmentity(entity);
    Map<String, Object> data = event.getDataMap();
    entity.setKey(entity.getTypeKey() + "-" + data.get(Constants.ID));
    entity.setName(data.get(Constants.FIRST_NAME) + " " + data.get(Constants.LAST_NAME));
    entity.setAvatarUrl(String.valueOf(data.get(Constants.IMAGE_URL)));
    if (StringUtils.isBlank(entity.getStateKey())) {
        entity.setStateKey(EntityState.NEW.name());
    }
    String startDate = String.valueOf(data.get(Constants.CREATED_DATE));
    if (StringUtils.isNotBlank(startDate)) {
        entity.setStartDate(Instant.parse(startDate));
    } else {
        entity.setStartDate(Instant.now());
    }
    String updateDate = String.valueOf(data.get(Constants.LAST_MODIFIED_DATE));
    if (StringUtils.isNotBlank(updateDate)) {
        entity.setUpdateDate(Instant.parse(updateDate));
    } else {
        entity.setUpdateDate(Instant.now());
    }
    profile.setUserKey(String.valueOf(data.get(Constants.USER_KEY)));
    entity.setData((Map<String, Object>) data.get(Constants.DATA));
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 3 with XmEntity

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

the class SystemEventMapperUnitTest method testMapProfileAlreadyExists.

@Test
public void testMapProfileAlreadyExists() {
    Long id = 1L;
    Profile profile = new Profile();
    profile.setId(id);
    profile.setXmentity(new XmEntity());
    profile.getXmentity().setStateKey(EntityState.ACTIVE.name());
    profile.getXmentity().setId(id);
    SystemEventMapper.toProfile(createEvent(), profile);
    assertNotNull(profile.getXmentity());
    assertEquals(id, profile.getId());
    assertEquals(id, profile.getXmentity().getId());
    assertEquals(DEFAULT_FIRST_NAME + " " + DEFAULT_LAST_NAME, profile.getXmentity().getName());
    assertEquals(Constants.ACCOUNT_TYPE_KEY + "-" + DEFAULT_ID, profile.getXmentity().getKey());
    assertEquals(DEFAULT_IMAGE_URL, profile.getXmentity().getAvatarUrl());
    assertEquals(EntityState.ACTIVE.name(), profile.getXmentity().getStateKey());
    assertNotNull(profile.getXmentity().getStartDate());
    assertNotNull(profile.getXmentity().getUpdateDate());
    assertEquals(DEFAULT_USER_KEY, profile.getUserKey());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Profile(com.icthh.xm.ms.entity.domain.Profile) Test(org.junit.Test)

Example 4 with XmEntity

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

the class ProfileServiceUnitTest method saveProfile.

@Test
public void saveProfile() {
    Profile profile = new Profile();
    profile.setId(ID);
    XmEntity xmEntity = new XmEntity();
    xmEntity.setId(ID);
    profile.setXmentity(xmEntity);
    when(profileRepository.save(profile)).thenReturn(profile);
    when(profileSearchRepository.save(profile)).thenReturn(profile);
    when(entitySearchRepository.save(profile.getXmentity())).thenReturn(profile.getXmentity());
    service.save(profile);
    verify(profileRepository).save(profile);
    verify(profileSearchRepository).save(profile);
    verify(entitySearchRepository).save(profile.getXmentity());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Profile(com.icthh.xm.ms.entity.domain.Profile) XmEntityResourceIntTest(com.icthh.xm.ms.entity.web.rest.XmEntityResourceIntTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with XmEntity

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

the class XmEntityGeneratorServiceIntTest method generateXmEntityWithRequiredDataFields.

@Test
@SneakyThrows
public void generateXmEntityWithRequiredDataFields() {
    XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity("TYPE3");
    log.info(new ObjectMapper().writeValueAsString(generatedEntity));
    Set<ConstraintViolation<XmEntity>> constraintViolations = validator.validate(generatedEntity);
    assertEquals(0, constraintViolations.size());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Aggregations

XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)102 Test (org.junit.Test)60 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)46 Transactional (org.springframework.transaction.annotation.Transactional)32 Link (com.icthh.xm.ms.entity.domain.Link)22 Tag (com.icthh.xm.ms.entity.domain.Tag)10 ConstraintViolation (javax.validation.ConstraintViolation)9 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SneakyThrows (lombok.SneakyThrows)8 Attachment (com.icthh.xm.ms.entity.domain.Attachment)7 Location (com.icthh.xm.ms.entity.domain.Location)7 lombok.val (lombok.val)7 Calendar (com.icthh.xm.ms.entity.domain.Calendar)6 Profile (com.icthh.xm.ms.entity.domain.Profile)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Rating (com.icthh.xm.ms.entity.domain.Rating)5 Timed (com.codahale.metrics.annotation.Timed)4