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