use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.
the class FacetFactory method createTermCluster.
private static <D extends DtObject> Map<FacetValue, DtList<D>> createTermCluster(final FacetDefinition facetDefinition, final DtList<D> dtList) {
// map résultat avec les docs par FacetFilter
final Map<FacetValue, DtList<D>> clusterValues = new LinkedHashMap<>();
// Cas des facettes par Term
final DtField dtField = facetDefinition.getDtField();
// on garde un index pour incrémenter le facetFilter pour chaque Term
final Map<Object, FacetValue> facetFilterIndex = new HashMap<>();
FacetValue facetValue;
for (final D dto : dtList) {
final Object value = dtField.getDataAccessor().getValue(dto);
facetValue = facetFilterIndex.get(value);
if (facetValue == null) {
final String valueAsString = dtField.getDomain().valueToString(value);
final String label;
if (StringUtil.isEmpty(valueAsString)) {
label = "<==no label==>";
} else {
label = valueAsString;
}
final MessageText labelMsg = MessageText.of(label);
// on garde la syntaxe Solr pour l'instant
final ListFilter listFilter = ListFilter.of(dtField.getName() + ":\"" + valueAsString + "\"");
facetValue = new FacetValue(label, listFilter, labelMsg);
facetFilterIndex.put(value, facetValue);
clusterValues.put(facetValue, new DtList<D>(dtList.getDefinition()));
}
clusterValues.get(facetValue).add(dto);
}
// tri des facettes
final Comparator<FacetValue> facetComparator = new FacetComparator<>(clusterValues);
final Map<FacetValue, DtList<D>> sortedFacetValues = new TreeMap<>(facetComparator);
sortedFacetValues.putAll(clusterValues);
return sortedFacetValues;
}
use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.
the class DtObjectJsonConverter method populateWebServiceCallContext.
/**
* {@inheritDoc}
*/
@Override
public void populateWebServiceCallContext(final Object input, final WebServiceParam webServiceParam, final WebServiceCallContext routeContext) {
final Class<?> paramClass = webServiceParam.getType();
Assertion.checkArgument(DtObject.class.isAssignableFrom(paramClass), "This JsonConverter can't read the asked type {0}. Only {1} is supported", paramClass.getSimpleName(), DtObject.class.getSimpleName());
Assertion.checkArgument(getSupportedInputs()[0].isInstance(input) || getSupportedInputs()[1].isInstance(input), "This JsonConverter doesn't support this input type {0}. Only {1} is supported", input.getClass().getSimpleName(), Arrays.toString(getSupportedInputs()));
// -----
final Type paramGenericType = webServiceParam.getGenericType();
final String objectPath;
final UiObject<DtObject> uiObject;
if (input instanceof String) {
uiObject = jsonReaderEngine.uiObjectFromJson((String) input, paramGenericType);
objectPath = "";
} else if (input instanceof UiContext) {
// cas des innerBodyParam
uiObject = (UiObject<DtObject>) ((UiContext) input).get(webServiceParam.getName());
objectPath = webServiceParam.getName();
} else {
throw new IllegalArgumentException(String.format("This JsonConverter can't read the asked type %s. Only %s is supported", paramClass.getSimpleName(), UiListDelta.class.getSimpleName()));
}
// -----
if (uiObject != null) {
// uiObject peut être null ici si optional
UiObjectUtil.postReadUiObject(uiObject, objectPath, webServiceParam);
}
routeContext.setParamValue(webServiceParam, uiObject);
}
use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.
the class SwaggerApiBuilder method createSchemaObject.
private Map<String, Object> createSchemaObject(final Type type) {
if (type == null) {
// Si le type est null, on a pas réussi à récupérer la class : souvant dans le cas des generics
return unknownObjectRef;
}
// -----
final Map<String, Object> schema = new LinkedHashMap<>();
final Class<?> objectClass = WebServiceTypeUtil.castAsClass(type);
final String[] typeAndFormat = toSwaggerType(objectClass);
schema.put("type", typeAndFormat[0]);
if (typeAndFormat[1] != null) {
schema.put("format", typeAndFormat[1]);
}
if (WebServiceTypeUtil.isAssignableFrom(Collection.class, type)) {
// we known that List has one parameterized type
final Type itemsType = ((ParameterizedType) type).getActualTypeArguments()[0];
// Si le itemsType est null, on prend le unknownObject
// type argument can't be void
schema.put("items", createSchemaObject(itemsType));
} else if ("object".equals(typeAndFormat[0])) {
final String objectName;
final Class<?> parameterClass;
if (type instanceof ParameterizedType && (((ParameterizedType) type).getActualTypeArguments().length == 1 || FacetedQueryResult.class.isAssignableFrom(objectClass)) && !(((ParameterizedType) type).getActualTypeArguments()[0] instanceof WildcardType)) {
// We have checked there is one parameter or we known that FacetedQueryResult has two parameterized type
final Type itemsType = ((ParameterizedType) type).getActualTypeArguments()[0];
parameterClass = WebServiceTypeUtil.castAsClass(itemsType);
objectName = objectClass.getSimpleName() + "<" + parameterClass.getSimpleName() + ">";
} else {
objectName = objectClass.getSimpleName();
parameterClass = null;
}
schema.put("$ref", "#/definitions/" + objectName);
schema.remove("type");
if (!builderDefinitions.containsKey(objectName)) {
final Map<String, Object> definition = new LinkedHashMap<>();
// we put definitions first to avoid infinite resolution loop
builderDefinitions.put(objectName, definition);
if (DtObject.class.isAssignableFrom(objectClass)) {
final Class<? extends DtObject> dtClass = (Class<? extends DtObject>) objectClass;
appendPropertiesDtObject(definition, dtClass);
} else {
appendPropertiesObject(definition, objectClass, parameterClass);
}
}
}
return schema;
}
use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.
the class UiErrorBuilder method checkFieldNotNull.
/**
* Vérifie que le champ est renseigner.
* @param dto Object a tester
* @param fieldName Champs
* @param messageText Message à appliquer si erreur
*/
public void checkFieldNotNull(final DtObject dto, final String fieldName, final MessageText messageText) {
final DtField dtField = getDtField(dto, fieldName);
final Object value = getValue(dto, dtField);
if (value == null || value.toString().isEmpty()) {
addError(dto, dtField, messageText);
}
}
use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.
the class GoogleJsonEngine method uiListFromJson.
/**
* {@inheritDoc}
*/
@Override
public <D extends DtObject> UiListModifiable<D> uiListFromJson(final String json, final Type paramType) {
// we known that DtList has one parameterized type
final Class<DtObject> dtoClass = (Class<DtObject>) ((ParameterizedType) paramType).getActualTypeArguments()[0];
final Type typeOfDest = createParameterizedType(UiListModifiable.class, dtoClass);
return gson.fromJson(json, typeOfDest);
}
Aggregations