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