Search in sources :

Example 21 with Entity

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DtObject(io.vertigo.dynamo.domain.model.DtObject) VFile(io.vertigo.dynamo.file.model.VFile)

Example 22 with Entity

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());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) Entity(io.vertigo.dynamo.domain.model.Entity) AccountGroup(io.vertigo.account.account.AccountGroup) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 23 with Entity

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());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 24 with Entity

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));
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) Matcher(java.util.regex.Matcher)

Example 25 with Entity

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;
}
Also used : Arrays(java.util.Arrays) ServerSideSave(io.vertigo.vega.webservice.stereotype.ServerSideSave) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) POST(io.vertigo.vega.webservice.stereotype.POST) Doc(io.vertigo.vega.webservice.stereotype.Doc) CriterionLimit(io.vertigo.dynamo.criteria.CriterionLimit) PathParam(io.vertigo.vega.webservice.stereotype.PathParam) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) Criterions(io.vertigo.dynamo.criteria.Criterions) Validate(io.vertigo.vega.webservice.stereotype.Validate) AccessTokenConsume(io.vertigo.vega.webservice.stereotype.AccessTokenConsume) MandatoryPkValidator(io.vertigo.vega.webservice.data.domain.MandatoryPkValidator) ContactValidator(io.vertigo.vega.webservice.data.domain.ContactValidator) Predicate(java.util.function.Predicate) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Collection(java.util.Collection) Set(java.util.Set) UiContext(io.vertigo.vega.engines.webservice.json.UiContext) Instant(java.time.Instant) QueryParam(io.vertigo.vega.webservice.stereotype.QueryParam) VFile(io.vertigo.dynamo.file.model.VFile) WebServices(io.vertigo.vega.webservice.WebServices) ExcludedFields(io.vertigo.vega.webservice.stereotype.ExcludedFields) Serializable(java.io.Serializable) GET(io.vertigo.vega.webservice.stereotype.GET) VUserException(io.vertigo.lang.VUserException) FileManager(io.vertigo.dynamo.file.FileManager) List(java.util.List) HeaderParam(io.vertigo.vega.webservice.stereotype.HeaderParam) DtObject(io.vertigo.dynamo.domain.model.DtObject) StringUtil(io.vertigo.util.StringUtil) Optional(java.util.Optional) ResourceManager(io.vertigo.core.resource.ResourceManager) DtField(io.vertigo.dynamo.domain.metamodel.DtField) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) AnonymousAccessAllowed(io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed) AccessTokenPublish(io.vertigo.vega.webservice.stereotype.AccessTokenPublish) ContactDao(io.vertigo.vega.webservice.data.domain.ContactDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InnerBodyParam(io.vertigo.vega.webservice.stereotype.InnerBodyParam) PathPrefix(io.vertigo.vega.webservice.stereotype.PathPrefix) DateUtil(io.vertigo.util.DateUtil) ServerSideRead(io.vertigo.vega.webservice.stereotype.ServerSideRead) PUT(io.vertigo.vega.webservice.stereotype.PUT) HttpServletResponse(javax.servlet.http.HttpServletResponse) AutoSortAndPagination(io.vertigo.vega.webservice.stereotype.AutoSortAndPagination) DtList(io.vertigo.dynamo.domain.model.DtList) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) ContactCriteria(io.vertigo.vega.webservice.data.domain.ContactCriteria) Entity(io.vertigo.dynamo.domain.model.Entity) EmptyPkValidator(io.vertigo.vega.webservice.data.domain.EmptyPkValidator) VCollectors(io.vertigo.dynamo.domain.util.VCollectors) Contact(io.vertigo.vega.webservice.data.domain.Contact) IncludedFields(io.vertigo.vega.webservice.stereotype.IncludedFields) AccessTokenMandatory(io.vertigo.vega.webservice.stereotype.AccessTokenMandatory) CollectionsManager(io.vertigo.dynamo.collections.CollectionsManager) Serializable(java.io.Serializable) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) HashSet(java.util.HashSet) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Predicate(java.util.function.Predicate)

Aggregations

Entity (io.vertigo.dynamo.domain.model.Entity)26 DtObject (io.vertigo.dynamo.domain.model.DtObject)10 URI (io.vertigo.dynamo.domain.model.URI)10 VFile (io.vertigo.dynamo.file.model.VFile)10 DtField (io.vertigo.dynamo.domain.metamodel.DtField)7 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)7 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 DtList (io.vertigo.dynamo.domain.model.DtList)4 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)4 Instant (java.time.Instant)4 Home (io.vertigo.app.Home)3 Criterions (io.vertigo.dynamo.criteria.Criterions)3 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)3 Assertion (io.vertigo.lang.Assertion)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Account (io.vertigo.account.account.Account)2 AccountGroup (io.vertigo.account.account.AccountGroup)2 AccountMapperHelper (io.vertigo.account.impl.account.AccountMapperHelper)2