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 };
}
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));
}
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());
}
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());
}
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());
}
Aggregations