Search in sources :

Example 1 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class CustomTranslationManagementServiceImplTest method shouldReturnCustomTranslationWhenGetCustomTranslationIfCustomTranslationIsntNull.

@Test
public void shouldReturnCustomTranslationWhenGetCustomTranslationIfCustomTranslationIsntNull() {
    // given
    String pluginIdentifier = "plugin";
    String key = "key";
    String locale = "pl";
    given(customTranslationDD.find()).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.add(Mockito.any(SearchCriterion.class))).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.setMaxResults(1)).willReturn(searchCriteriaBuilder);
    given(searchCriteriaBuilder.uniqueResult()).willReturn(customTranslation);
    // when
    Entity result = customTranslationManagementService.getCustomTranslation(pluginIdentifier, key, locale);
    // then
    assertEquals(customTranslation, result);
}
Also used : Entity(com.qcadoo.model.api.Entity) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class CustomTranslationCacheServiceImpl method loadCustomTranslations.

@Override
public void loadCustomTranslations(final List<Entity> customTranslations) {
    for (Entity customTranslation : customTranslations) {
        boolean active = customTranslation.getBooleanField(ACTIVE);
        String key = customTranslation.getStringField(KEY);
        String translation = customTranslation.getStringField(CustomTranslationFields.CUSTOM_TRANSLATION);
        String locale = (active) ? customTranslation.getStringField(LOCALE) : null;
        manageCustomTranslation(key, locale, translation);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 3 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class PdfHelperImpl method getDocumentAuthor.

@Override
public String getDocumentAuthor() {
    Entity user = dataDefinitionService.get(QCADOO_SECURITY, USER).get(securityService.getCurrentUserId());
    String firstName = user.getStringField(FIRST_NAME);
    String lastName = user.getStringField(LAST_NAME);
    String userName = user.getStringField(USER_NAME);
    String documentAuthor = "";
    if (!StringUtils.isEmpty(firstName)) {
        documentAuthor += firstName;
    }
    if (!StringUtils.isEmpty(lastName)) {
        if (StringUtils.isEmpty(documentAuthor)) {
            documentAuthor += lastName;
        } else {
            documentAuthor += " " + lastName;
        }
    }
    if (StringUtils.isEmpty(documentAuthor)) {
        documentAuthor = userName;
    } else {
        documentAuthor += " (" + userName + ")";
    }
    return documentAuthor;
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 4 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class SecurityServiceImpl method hasCurrentUserRole.

@Override
public boolean hasCurrentUserRole(final String targetRoleIdentifier) {
    checkNotNull(targetRoleIdentifier, L_TARGET_ROLE_IDENTIFIER_MUST_BE_GIVEN);
    Entity user = getUserEntity(getCurrentUserName());
    Entity group = user.getBelongsToField(UserFields.GROUP);
    return getGroupDD().find().createAlias(GroupFields.ROLES, GroupFields.ROLES, JoinType.LEFT).add(SearchRestrictions.eq("id", group.getId())).add(SearchRestrictions.eq(GroupFields.ROLES + "." + RoleFields.IDENTIFIER, targetRoleIdentifier)).list().getTotalNumberOfEntities() > 0;
}
Also used : Entity(com.qcadoo.model.api.Entity)

Example 5 with Entity

use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.

the class SecurityServiceImpl method getCurrentUserName.

@Override
@Monitorable
public String getCurrentUserName() {
    SecurityContext context = getContext();
    Authentication authentication = getAuthentication();
    if (Objects.isNull(context) || Objects.isNull(authentication) || Objects.isNull(authentication.getName())) {
        return null;
    }
    String userName = authentication.getName();
    Entity user = getUserEntity(userName);
    return user.getStringField(UserFields.USER_NAME);
}
Also used : Entity(com.qcadoo.model.api.Entity) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Aggregations

Entity (com.qcadoo.model.api.Entity)2833 FormComponent (com.qcadoo.view.api.components.FormComponent)514 Test (org.junit.Test)491 BigDecimal (java.math.BigDecimal)376 DataDefinition (com.qcadoo.model.api.DataDefinition)337 FieldComponent (com.qcadoo.view.api.components.FieldComponent)210 LookupComponent (com.qcadoo.view.api.components.LookupComponent)188 Date (java.util.Date)185 List (java.util.List)149 GridComponent (com.qcadoo.view.api.components.GridComponent)141 Map (java.util.Map)124 Autowired (org.springframework.beans.factory.annotation.Autowired)114 Service (org.springframework.stereotype.Service)112 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)105 Transactional (org.springframework.transaction.annotation.Transactional)101 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)100 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)95 Collectors (java.util.stream.Collectors)87 Lists (com.google.common.collect.Lists)75 SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)75