use of io.vertigo.dynamo.domain.model.Entity in project vertigo by KleeGroup.
the class FsFileStorePlugin method createFileInfoEntity.
private Entity createFileInfoEntity(final FileInfo fileInfo) {
final Entity fileInfoDto = createFileInfoEntity(fileInfo.getDefinition());
// -----
final VFile vFile = fileInfo.getVFile();
setValue(fileInfoDto, DtoFields.FILE_NAME, vFile.getFileName());
setValue(fileInfoDto, DtoFields.MIME_TYPE, vFile.getMimeType());
setValue(fileInfoDto, DtoFields.LAST_MODIFIED, vFile.getLastModified());
setValue(fileInfoDto, DtoFields.LENGTH, vFile.getLength());
if (fileInfo.getURI() == null) {
// cas de la création, on ajoute en base un chemin fictif (colonne not null)
setValue(fileInfoDto, DtoFields.FILE_PATH, "/dev/null");
} else {
// cas de l'update
setIdValue(fileInfoDto, fileInfo.getURI().getKey());
// récupération de l'objet en base pour récupérer le path du fichier et ne pas modifier la base
final URI<Entity> dtoUri = createDtObjectURI(fileInfo.getURI());
final DtObject fileInfoDtoBase = getStoreManager().getDataStore().readOne(dtoUri);
final String pathToSave = getValue(fileInfoDtoBase, DtoFields.FILE_PATH, String.class);
setValue(fileInfoDto, DtoFields.FILE_PATH, pathToSave);
}
return fileInfoDto;
}
use of io.vertigo.dynamo.domain.model.Entity in project vertigo by KleeGroup.
the class StoreAccountStorePlugin method getGroupURIs.
/**
* {@inheritDoc}
*/
@Override
public Set<URI<AccountGroup>> getGroupURIs(final URI<Account> accountURI) {
if (associationUserGroup instanceof AssociationSimpleDefinition) {
// case 1 group per user
final URI<Entity> userURI = new URI(getUserDtDefinition(), accountURI.getId());
final Entity userEntity = storeManager.getDataStore().readOne(userURI);
final Object fkValue = ((AssociationSimpleDefinition) associationUserGroup).getFKField().getDataAccessor().getValue(userEntity);
final URI<AccountGroup> groupURI = new URI(userGroupDtDefinition, fkValue);
return Collections.singleton(groupURI);
}
// case N group per user
// other case checked in postStart by assertions
Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
final DtListURI groupDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, accountURI, associationGroupRoleName);
// -----
final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(groupDtListURI);
return result.stream().map(groupEntity -> groupToAccount(groupEntity).getURI()).collect(Collectors.toSet());
}
use of io.vertigo.dynamo.domain.model.Entity in project vertigo by KleeGroup.
the class StoreAccountStorePlugin method getAccountURIs.
/**
* {@inheritDoc}
*/
@Override
public Set<URI<Account>> getAccountURIs(final URI<AccountGroup> groupURI) {
final DtListURI userDtListURI;
if (associationUserGroup instanceof AssociationSimpleDefinition) {
userDtListURI = new DtListURIForSimpleAssociation((AssociationSimpleDefinition) associationUserGroup, groupURI, associationUserRoleName);
} else {
// autres cas éliminés par assertion dans le postStart
Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
userDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, groupURI, associationUserRoleName);
}
// -----
final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(userDtListURI);
return result.stream().map(userEntity -> userToAccount(userEntity).getURI()).collect(Collectors.toSet());
}
use of io.vertigo.dynamo.domain.model.Entity in project vertigo by KleeGroup.
the class TextIdentityProviderPlugin method parseUserInfo.
private void parseUserInfo(final String line, final DtDefinition userDtDefinition) throws FormatterException {
final Matcher matcher = filePattern.matcher(line);
String photoUrl = null;
String userAuthToken = null;
final Entity user = Entity.class.cast(DtObjectUtil.createDtObject(userDtDefinition));
for (final String propertyName : filePatternFieldsOrdered) {
final String valueStr = matcher.group(propertyName);
if (PHOTO_URL_RESERVED_FIELD.equals(propertyName)) {
photoUrl = valueStr;
} else {
setTypedValue(userDtDefinition, user, propertyName, valueStr);
if (userAuthTokenFieldName.equals(propertyName)) {
userAuthToken = valueStr;
}
}
}
Assertion.checkArgNotEmpty(userAuthToken, "User AuthToken not found");
users.put(userAuthToken, new IdentityUserInfo(user, photoUrl));
}
use of io.vertigo.dynamo.domain.model.Entity in project vertigo by KleeGroup.
the class AdvancedTestWebServices method createFilterFunction.
private <C extends DtObject, E extends Entity> Predicate<E> createFilterFunction(final C criteria, final Class<E> resultClass) {
Predicate<E> filter = (o) -> true;
final DtDefinition criteriaDefinition = DtObjectUtil.findDtDefinition(criteria);
final DtDefinition resultDefinition = DtObjectUtil.findDtDefinition(resultClass);
final Set<String> alreadyAddedField = new HashSet<>();
for (final DtField field : criteriaDefinition.getFields()) {
final String fieldName = field.getName();
if (!alreadyAddedField.contains(fieldName)) {
// when we consume two fields at once (min;max)
final Object value = field.getDataAccessor().getValue(criteria);
if (value != null) {
if (fieldName.endsWith("_MIN") || fieldName.endsWith("_MAX")) {
final String filteredField = fieldName.substring(0, fieldName.length() - "_MIN".length());
final DtField resultDtField = resultDefinition.getField(filteredField);
final DtField minField = fieldName.endsWith("_MIN") ? field : criteriaDefinition.getField(filteredField + "_MIN");
final DtField maxField = fieldName.endsWith("_MAX") ? field : criteriaDefinition.getField(filteredField + "_MAX");
final Serializable minValue = (Serializable) minField.getDataAccessor().getValue(criteria);
final Serializable maxValue = (Serializable) maxField.getDataAccessor().getValue(criteria);
filter = filter.and(Criterions.isBetween(() -> resultDtField.getName(), CriterionLimit.ofIncluded(minValue), CriterionLimit.ofExcluded(maxValue)).toPredicate());
} else {
final Predicate predicate = Criterions.isEqualTo(() -> fieldName, Serializable.class.cast(value)).toPredicate();
filter.and(predicate);
}
}
}
// si null, alors on ne filtre pas
}
return filter;
}
Aggregations