Search in sources :

Example 21 with XmEntity

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());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Test(org.junit.Test)

Example 22 with XmEntity

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());
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Test(org.junit.Test)

Example 23 with XmEntity

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();
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Example 24 with XmEntity

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;
    }
}
Also used : Set(java.util.Set) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity)

Example 25 with XmEntity

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;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Profile(com.icthh.xm.ms.entity.domain.Profile)

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