use of com.robo4j.socket.http.dto.ResponseAttributeDTO in project robo4j by Robo4J.
the class RoboRequestFactory method processGet.
// FIXME correct available methods according to the configuration
@Override
public Object processGet(ServerPathConfig pathConfig) {
final RoboReference<?> unitRef = pathConfig.getRoboUnit();
final SocketDecoder<?, ?> decoder = codecRegistry.getDecoder(unitRef.getMessageType());
if (unitRef.getMessageType().equals(Object.class) || decoder == null) {
List<ResponseAttributeDTO> attrList = unitRef.getKnownAttributes().stream().map(d -> {
try {
Object val = unitRef.getAttribute(d).get();
ResponseAttributeDTO attributeDTO = new ResponseAttributeDTO();
attributeDTO.setId(d.getAttributeName());
attributeDTO.setType(d.getAttributeType().getTypeName());
attributeDTO.setValue(String.valueOf(val));
if (d.getAttributeName().equals(HttpServerUnit.ATTR_PATHS)) {
attributeDTO.setType("java.util.ArrayList");
}
return attributeDTO;
} catch (InterruptedException | ExecutionException e) {
SimpleLoggingUtil.error(getClass(), e.getMessage());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
return JsonUtil.toJsonArrayServer(attrList);
} else {
final ResponseDecoderUnitDTO result = new ResponseDecoderUnitDTO();
result.setId(unitRef.getId());
result.setCodec(decoder.getDecodedClass().getName());
result.setMethods(GET_POST_METHODS);
return ReflectUtils.createJson(result);
}
}
use of com.robo4j.socket.http.dto.ResponseAttributeDTO in project robo4j by Robo4J.
the class JsonUtil method toJsonArrayServer.
public static <T> String toJsonArrayServer(List<T> list) {
return JsonElementStringBuilder.Builder().add(Utf8Constant.UTF8_SQUARE_BRACKET_LEFT).add(list.stream().map(e -> {
if (e instanceof ResponseAttributeDTO) {
ResponseAttributeDTO ra = (ResponseAttributeDTO) e;
switch(ra.getType()) {
case "java.util.ArrayList":
List<HttpPathMethodDTO> tmpList = JsonUtil.readPathConfig(HttpPathMethodDTO.class, ra.getValue());
ResponseAttributeListDTO tmpAttr = new ResponseAttributeListDTO();
tmpAttr.setId(ra.getId());
tmpAttr.setType(ra.getType());
tmpAttr.setValue(tmpList);
return ReflectUtils.createJson(tmpAttr);
default:
return ReflectUtils.createJson(e);
}
} else {
return ReflectUtils.createJson(e);
}
}).collect(Collectors.joining(Utf8Constant.UTF8_COMMA))).add(Utf8Constant.UTF8_SQUARE_BRACKET_RIGHT).build();
}
Aggregations