Search in sources :

Example 16 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject 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 17 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class StoreAuthenticationPlugin method authenticateAccount.

/**
 * {@inheritDoc}
 */
@Override
public Optional<String> authenticateAccount(final AuthenticationToken token) {
    final Criteria criteriaByLogin = Criterions.isEqualTo(() -> userLoginField, token.getPrincipal());
    final DtList<DtObject> results = storeManager.getDataStore().find(userCredentialDefinition, criteriaByLogin);
    // may ensure, that valid or invalid login took the same time, so we don't assert no result here
    Assertion.checkState(results.size() <= 1, "Too many matching credentials for {0}", token.getPrincipal());
    final AuthenticationToken trustedAuthenticationToken;
    if (token instanceof UsernamePasswordAuthenticationToken) {
        if (results.isEmpty()) {
            trustedAuthenticationToken = defaultUserTrustedCredential;
        } else {
            final String trustedEncodedPassword = (String) userCredentialDefinition.getField(userPasswordField).getDataAccessor().getValue(results.get(0));
            trustedAuthenticationToken = new UsernamePasswordAuthenticationToken(token.getPrincipal(), trustedEncodedPassword);
        }
    } else {
        if (results.isEmpty()) {
            trustedAuthenticationToken = defaultUserTrustedCredential;
        } else {
            trustedAuthenticationToken = new UsernameAuthenticationToken(token.getPrincipal());
        }
    }
    // may ensure, that valid or invalid login took the same time, so we don't assert no result here
    if (// tokens match
    token.match(trustedAuthenticationToken) && !results.isEmpty()) {
        // and Username exists (after)
        final String userTokenId = (String) userCredentialDefinition.getField(userTokenIdField).getDataAccessor().getValue(results.get(0));
        return Optional.of(userTokenId);
    }
    return Optional.empty();
}
Also used : UsernameAuthenticationToken(io.vertigo.account.impl.authentication.UsernameAuthenticationToken) UsernamePasswordAuthenticationToken(io.vertigo.account.impl.authentication.UsernamePasswordAuthenticationToken) AuthenticationToken(io.vertigo.account.authentication.AuthenticationToken) DtObject(io.vertigo.dynamo.domain.model.DtObject) UsernameAuthenticationToken(io.vertigo.account.impl.authentication.UsernameAuthenticationToken) UsernamePasswordAuthenticationToken(io.vertigo.account.impl.authentication.UsernamePasswordAuthenticationToken) Criteria(io.vertigo.dynamo.criteria.Criteria)

Example 18 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class RamLuceneIndex method addAll.

/**
 * Add element to index.
 * @param fullDtc Full Dtc to index
 * @param storeValue if data are store in index
 * @throws IOException Indexation error
 */
public void addAll(final DtList<D> fullDtc, final boolean storeValue) throws IOException {
    Assertion.checkNotNull(fullDtc);
    // -----
    try (final IndexWriter indexWriter = createIndexWriter()) {
        final DtField idField = fullDtc.getDefinition().getIdField().get();
        final Collection<DtField> dtFields = fullDtc.getDefinition().getFields();
        for (final D dto : fullDtc) {
            final Document document = new Document();
            final Object pkValue = idField.getDataAccessor().getValue(dto);
            Assertion.checkNotNull(pkValue, "Indexed DtObject must have a not null primary key. {0}.{1} was null.", fullDtc.getDefinition().getName(), idField.getName());
            final String indexedPkValue = String.valueOf(pkValue);
            addKeyword(document, idField.getName(), indexedPkValue, true);
            for (final DtField dtField : dtFields) {
                final Object value = dtField.getDataAccessor().getValue(dto);
                if (value != null && !dtField.equals(idField)) {
                    if (value instanceof String) {
                        final String valueAsString = getStringValue(dto, dtField);
                        addIndexed(document, dtField.getName(), valueAsString, storeValue);
                    } else if (value instanceof Date) {
                        final String valueAsString = DateTools.dateToString((Date) value, DateTools.Resolution.DAY);
                        addKeyword(document, dtField.getName(), valueAsString, storeValue);
                    } else {
                        addKeyword(document, dtField.getName(), value.toString(), storeValue);
                    }
                }
            }
            indexWriter.addDocument(document);
            mapDocument(indexedPkValue, dto);
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) DtObject(io.vertigo.dynamo.domain.model.DtObject) Document(org.apache.lucene.document.Document) Date(java.util.Date) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 19 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class ESDocumentCodec method index2XContentBuilder.

/**
 * Transformation d'un index en un document ElasticSearch.
 * @param <S> Type du sujet représenté par ce document
 * @param <I> Type d'object indexé
 * @param index Objet logique de recherche
 * @return Document SOLR
 * @throws IOException Json exception
 */
<S extends KeyConcept, I extends DtObject> XContentBuilder index2XContentBuilder(final SearchIndex<S, I> index) throws IOException {
    Assertion.checkNotNull(index);
    // -----
    final DtDefinition dtDefinition = index.getDefinition().getIndexDtDefinition();
    // on ne copie pas les champs not stored dans le domain
    final List<DtField> notStoredFields = getNotStoredFields(dtDefinition);
    // on ne copie pas les champs (copyTo)
    notStoredFields.addAll(index.getDefinition().getIndexCopyToFields());
    final I dtResult;
    if (notStoredFields.isEmpty()) {
        dtResult = index.getIndexDtObject();
    } else {
        dtResult = cloneDto(dtDefinition, index.getIndexDtObject(), notStoredFields);
    }
    /* 2: Result stocké */
    final String result = encode(dtResult);
    /* 1 : URI */
    try (final XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
        xContentBuilder.startObject().field(FULL_RESULT, result);
        /* 3 : Les champs du dto index */
        final DtObject dtIndex = index.getIndexDtObject();
        final DtDefinition indexDtDefinition = DtObjectUtil.findDtDefinition(dtIndex);
        final Set<DtField> copyToFields = index.getDefinition().getIndexCopyToFields();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            if (!copyToFields.contains(dtField)) {
                // On index pas les copyFields
                final Object value = dtField.getDataAccessor().getValue(dtIndex);
                if (value != null) {
                    // les valeurs null ne sont pas indexées => conséquence : on ne peut pas les rechercher
                    final String indexFieldName = dtField.getName();
                    if (value instanceof String) {
                        final String encodedValue = escapeInvalidUTF8Char((String) value);
                        xContentBuilder.field(indexFieldName, encodedValue);
                    } else {
                        xContentBuilder.field(indexFieldName, value);
                    }
                }
            }
        }
        return xContentBuilder.endObject();
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObject(io.vertigo.dynamo.domain.model.DtObject) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 20 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class SearchManagerMultiIndexTest method query.

private long query(final String query, final SearchIndexDefinition indexDefinition) {
    // recherche
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of(query)).build();
    final FacetedQueryResult<DtObject, SearchQuery> result = searchManager.loadList(indexDefinition, searchQuery, null);
    return result.getCount();
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) DtObject(io.vertigo.dynamo.domain.model.DtObject)

Aggregations

DtObject (io.vertigo.dynamo.domain.model.DtObject)32 DtField (io.vertigo.dynamo.domain.metamodel.DtField)14 Entity (io.vertigo.dynamo.domain.model.Entity)9 URI (io.vertigo.dynamo.domain.model.URI)8 Type (java.lang.reflect.Type)8 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 DtList (io.vertigo.dynamo.domain.model.DtList)5 ParameterizedType (java.lang.reflect.ParameterizedType)5 VFile (io.vertigo.dynamo.file.model.VFile)4 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)4 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)4 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)3 Instant (java.time.Instant)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 JsonObject (com.google.gson.JsonObject)2 CollectionsManager (io.vertigo.dynamo.collections.CollectionsManager)2