Search in sources :

Example 1 with ResponseUnitDTO

use of com.robo4j.socket.http.dto.ResponseUnitDTO in project robo4j by Robo4J.

the class RoboRequestFactory method processGet.

/**
 * Generic robo context overview. It returns all units registered into the context including system id.
 * The 1st position is reserved for the system
 *
 * @param context
 *            robo context
 * @return descripton of desired context
 */
@Override
public Object processGet(RoboContext context) {
    if (!context.getUnits().isEmpty()) {
        final List<ResponseUnitDTO> unitList = context.getUnits().stream().map(u -> new ResponseUnitDTO(u.getId(), u.getState())).collect(Collectors.toList());
        unitList.add(0, new ResponseUnitDTO(context.getId(), context.getState()));
        return JsonUtil.toJsonArray(unitList);
    } else {
        SimpleLoggingUtil.error(getClass(), "internal error: no units available");
    }
    return null;
}
Also used : SimpleLoggingUtil(com.robo4j.logging.SimpleLoggingUtil) CodecRegistry(com.robo4j.socket.http.units.CodecRegistry) Arrays(java.util.Arrays) ServerPathConfig(com.robo4j.socket.http.units.ServerPathConfig) Collectors(java.util.stream.Collectors) ResponseUnitDTO(com.robo4j.socket.http.dto.ResponseUnitDTO) ResponseAttributeDTO(com.robo4j.socket.http.dto.ResponseAttributeDTO) JsonUtil(com.robo4j.socket.http.util.JsonUtil) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) HttpServerUnit(com.robo4j.socket.http.units.HttpServerUnit) List(java.util.List) SocketDecoder(com.robo4j.socket.http.units.SocketDecoder) HttpMethod(com.robo4j.socket.http.HttpMethod) RoboContext(com.robo4j.RoboContext) RoboReference(com.robo4j.RoboReference) ResponseDecoderUnitDTO(com.robo4j.socket.http.dto.ResponseDecoderUnitDTO) ReflectUtils(com.robo4j.socket.http.util.ReflectUtils) ResponseUnitDTO(com.robo4j.socket.http.dto.ResponseUnitDTO)

Example 2 with ResponseUnitDTO

use of com.robo4j.socket.http.dto.ResponseUnitDTO in project robo4j by Robo4J.

the class JsonUtilTests method jsonToListTest.

@Test
void jsonToListTest() {
    String json = "[{\"id\":\"unit1\",\"state\":\"INITIALIZED\"}," + "{\"id\":\"unit2\",\"state\":\"STARTED\"}, " + "{\"id\":\"unit3\",\"state\":\"FAILED\"}]";
    List<ResponseUnitDTO> expectedResult = Arrays.asList(new ResponseUnitDTO("unit1", LifecycleState.INITIALIZED), new ResponseUnitDTO("unit2", LifecycleState.STARTED), new ResponseUnitDTO("unit3", LifecycleState.FAILED));
    List<ResponseUnitDTO> result = JsonUtil.jsonToList(ResponseUnitDTO.class, json);
    assertNotNull(result);
    assertArrayEquals(expectedResult.toArray(), result.toArray());
}
Also used : ResponseUnitDTO(com.robo4j.socket.http.dto.ResponseUnitDTO) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseUnitDTO (com.robo4j.socket.http.dto.ResponseUnitDTO)2 RoboContext (com.robo4j.RoboContext)1 RoboReference (com.robo4j.RoboReference)1 SimpleLoggingUtil (com.robo4j.logging.SimpleLoggingUtil)1 HttpMethod (com.robo4j.socket.http.HttpMethod)1 ResponseAttributeDTO (com.robo4j.socket.http.dto.ResponseAttributeDTO)1 ResponseDecoderUnitDTO (com.robo4j.socket.http.dto.ResponseDecoderUnitDTO)1 CodecRegistry (com.robo4j.socket.http.units.CodecRegistry)1 HttpServerUnit (com.robo4j.socket.http.units.HttpServerUnit)1 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)1 SocketDecoder (com.robo4j.socket.http.units.SocketDecoder)1 JsonUtil (com.robo4j.socket.http.util.JsonUtil)1 ReflectUtils (com.robo4j.socket.http.util.ReflectUtils)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.jupiter.api.Test)1