use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class AvatarUrlListenerUnitTest method testPrePersistSuccess.
@Test
public void testPrePersistSuccess() {
XmEntity entity = new XmEntity().avatarUrl("http://hello.rgw.icthh.test/hello.jpg");
target.prePersist(entity);
assertEquals("hello.jpg", entity.getAvatarUrl());
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class AvatarUrlListenerUnitTest method testPrePersistWrongFormat.
@Test
public void testPrePersistWrongFormat() {
XmEntity entity = new XmEntity().avatarUrl("hello.jpg");
target.prePersist(entity);
assertEquals(null, entity.getAvatarUrl());
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class XmEntityUtils method getLinkedTarget.
public static Optional<XmEntity> getLinkedTarget(XmEntity xmEntity, String linkTypeKey, String linkTargetTypeKey) {
Optional<Link> firstLink = findFirstLink(xmEntity, linkTypeKey);
if (firstLink.isPresent()) {
Link link = firstLink.get();
XmEntity target = Objects.requireNonNull(link.getTarget(), "Link with type key '" + linkTypeKey + "' has null target");
if (Objects.equals(target.getTypeKey(), linkTargetTypeKey)) {
return Optional.of(target);
}
}
return Optional.empty();
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class TypeKeyValidator method isValid.
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
try {
String typeKey = (String) FieldUtils.readField(value, typeKeyField, true);
if (value instanceof XmEntity) {
return xmEntitySpecService.getAllKeys().containsKey(typeKey);
} else {
XmEntity entity = (XmEntity) FieldUtils.readField(value, entityField, true);
if (entity == null) {
return true;
}
String entityTypeKey = entity.getTypeKey();
Map<String, Set<String>> keysByEntityType = xmEntitySpecService.getAllKeys().get(entityTypeKey);
return !(keysByEntityType == null || keysByEntityType.get(getClassName(value)) == null) && keysByEntityType.get(getClassName(value)).contains(typeKey);
}
} catch (IllegalAccessException e) {
log.debug("Could not get keys for validation", e);
return false;
}
}
use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.
the class TenantDatabaseService method buildProfileForDefaultUser.
private Profile buildProfileForDefaultUser(String tenantKey) {
XmEntity entity = new XmEntity();
entity.setTypeKey("ACCOUNT.USER");
entity.setKey("ACCOUNT.USER-1");
entity.setName("Administrator");
entity.setStateKey(EntityState.NEW.name());
entity.setStartDate(Instant.now());
entity.setUpdateDate(Instant.now());
entity.setCreatedBy(Constants.SYSTEM_ACCOUNT);
Profile profile = new Profile();
profile.setXmentity(entity);
profile.setUserKey(tenantKey.toLowerCase());
return profile;
}
Aggregations