Jaspersoft / jrs-rest-java-client

Java Rest Client for JasperReports Server
GNU Lesser General Public License v3.0
100 stars 102 forks source link

Remove DTOs from the client. #35

Open Krasnyanskiy opened 10 years ago

Krasnyanskiy commented 10 years ago

Maybe we should move all DTOs into the single jar file? It would be useful for testing.

mortias commented 10 years ago

indeed, so i can also use it via jms as a seporate dependency, then they should implement a interface a TransferObject that extends Serializable ?

mortias commented 10 years ago

also then you can create a typesafe client template to reduce boiler plate code (open/close sessions)

Krasnyanskiy commented 10 years ago

Hi Mortias, What do you mean by "typesafe client template"? Could you please explain me?

mortias commented 10 years ago

never mind :) what i try to do is templating, i wanted to make it typesafe but there is no sense to it.. i tweaked the RestClientConfiguration so i can drag my admin pwd everywhere

public class ClientTemplate {

public Session session = null;

private JasperserverRestClient client;
private JRRestClientConfiguration config;

public static final Log log = LogFactory.getLog(ClientTemplate.class);

public ClientTemplate() {
    config = JRRestClientConfiguration.loadConfiguration("config/jasper.properties");
    client = new JasperserverRestClient(config);
}

public Object process(StackTraceElement stackTraceElement, String requestId, ClientProcessor processor) {

    Object result = null;

    try {

        session = client.authenticate(config.getAdminUserName(), config.getAdminUserPassword());

        long startTime = System.nanoTime();

        result = processor.process(session, requestId);

        long endTime = System.nanoTime();
        long duration = (endTime - startTime);

        log.info(stackTraceElement.getMethodName() + ", " + duration / 1000000 + " ms");

    } catch (Exception e) {
        e.printStackTrace();
        log.error(stackTraceElement.getClassName() + ", " + stackTraceElement.getMethodName() + ", error: " + e.getCause());

    } finally {
        if (session != null)
            session.logout();
    }

    return result;

}

}

mortias commented 10 years ago

@Test // The resources service, when resources() method used without specifying any repository URI, // is used to search the repository. The various parameters let you refine the search and specify // how you receive search results. public void findResources() {

    ClientResourceListWrapper result = (ClientResourceListWrapper) clientTemplate.process(
            Thread.currentThread().getStackTrace()[1], "",
            new ClientProcessor() {
                @Override
                public ClientResourceListWrapper process(Session session, String requestId) throws Exception {

                    BatchResourcesAdapter query = session.resourcesService().resources();

                    // query.parameter(ResourceSearchParameter.Q, "");
                    query.parameter(ResourceSearchParameter.RECURSIVE, "true");
                    query.parameter(ResourceSearchParameter.FOLDER_URI, "/dev/portal/ercmice/map_security");
                    query.parameter(ResourceSearchParameter.SHOW_HIDDEN_ITEMS, "true");

                    ClientResourceListWrapper resourceListWrapper = query.search().getEntity();
                    return resourceListWrapper != null ? resourceListWrapper : new ClientResourceListWrapper();

                }
            });

    if (result.getResourceLookups() != null)
        for (ClientResourceLookup lookup : result.getResourceLookups())
            log.info(lookup.toString());
}
Krasnyanskiy commented 10 years ago

Very interesting customization.

mortias commented 10 years ago

Tx, the idea then of using dto's is in the context of a microservice architecture that has a reporting service. Where this rest client is embedded and triggered by a camel flow. Dto's define the contract to be used on the different interfaces like a jaxrs jaxws or jms the service provides. Maybe a feature request could also be to create a camel component!