Search in sources :

Example 1 with PersonNetwork

use of org.alfresco.rest.api.model.PersonNetwork in project alfresco-remote-api by Alfresco.

the class NetworksImpl method getNetwork.

public PersonNetwork getNetwork(String personId, String networkId) {
    // check that personId is the current user
    personId = people.validatePerson(personId, true);
    Network network = validateNetwork(networkId);
    org.alfresco.repo.tenant.Network tenantNetwork = networksService.getNetwork(network.getId());
    PersonNetwork personNetwork = getPersonNetwork(tenantNetwork);
    return personNetwork;
}
Also used : Network(org.alfresco.rest.api.model.Network) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork)

Example 2 with PersonNetwork

use of org.alfresco.rest.api.model.PersonNetwork in project alfresco-remote-api by Alfresco.

the class NetworksImpl method getNetworks.

public CollectionWithPagingInfo<PersonNetwork> getNetworks(String personId, Paging paging) {
    // check that personId is the current user
    personId = people.validatePerson(personId, true);
    PagingResults<org.alfresco.repo.tenant.Network> networks = networksService.getNetworks(Util.getPagingRequest(paging));
    List<PersonNetwork> ret = new ArrayList<PersonNetwork>(networks.getPage().size());
    for (org.alfresco.repo.tenant.Network network : networks.getPage()) {
        PersonNetwork personNetwork = getPersonNetwork(network);
        ret.add(personNetwork);
    }
    return CollectionWithPagingInfo.asPaged(paging, ret, networks.hasMoreItems(), networks.getTotalResultCount().getFirst());
}
Also used : Network(org.alfresco.rest.api.model.Network) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) ArrayList(java.util.ArrayList) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork)

Example 3 with PersonNetwork

use of org.alfresco.rest.api.model.PersonNetwork in project alfresco-remote-api by Alfresco.

the class NetworksImpl method getPersonNetwork.

private PersonNetwork getPersonNetwork(org.alfresco.repo.tenant.Network network) {
    Network restNetwork = new NetworkImpl(network);
    PersonNetwork personNetwork = new PersonNetwork(network.getIsHomeNetwork(), restNetwork);
    return personNetwork;
}
Also used : Network(org.alfresco.rest.api.model.Network) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) NetworkImpl(org.alfresco.rest.api.model.NetworkImpl) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork)

Example 4 with PersonNetwork

use of org.alfresco.rest.api.model.PersonNetwork in project alfresco-remote-api by Alfresco.

the class NetworkWebScriptGet method execute.

@Override
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException {
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                // apply content type
                res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
                assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer() {

                    @Override
                    public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
                        String personId = AuthenticationUtil.getFullyAuthenticatedUser();
                        String networkId = TenantUtil.getCurrentDomain();
                        PersonNetwork networkMembership = networks.getNetwork(personId, networkId);
                        if (networkMembership != null) {
                            // TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
                            // done automatically by the api framework).
                            Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMembership);
                            objectMapper.writeValue(generator, wrapped);
                        } else {
                            throw new EntityNotFoundException(networkId);
                        }
                    }
                });
                return null;
            }
        }, true, true);
    } catch (ApiException | WebScriptException apiException) {
        renderException(apiException, res, assistant);
    } catch (RuntimeException runtimeException) {
        renderException(runtimeException, res, assistant);
    }
}
Also used : EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) ResponseWriter(org.alfresco.rest.framework.tools.ResponseWriter) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 5 with PersonNetwork

use of org.alfresco.rest.api.model.PersonNetwork in project alfresco-remote-api by Alfresco.

the class NetworksWebScriptGet method execute.

@Override
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException {
    try {
        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

            @Override
            public Void execute() throws Throwable {
                final Paging paging = findPaging(req);
                // apply content type
                res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
                assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer() {

                    @Override
                    public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
                        List<Object> entities = new ArrayList<Object>();
                        String personId = AuthenticationUtil.getFullyAuthenticatedUser();
                        CollectionWithPagingInfo<PersonNetwork> networkMemberships = networks.getNetworks(personId, paging);
                        for (PersonNetwork networkMember : networkMemberships.getCollection()) {
                            // TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
                            // done automatically by the api framework).
                            Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMember);
                            entities.add(wrapped);
                        }
                        objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(paging, entities));
                    }
                });
                return null;
            }
        }, true, true);
    } catch (ApiException | WebScriptException apiException) {
        renderException(apiException, res, assistant);
    } catch (RuntimeException runtimeException) {
        renderException(runtimeException, res, assistant);
    }
}
Also used : Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) PersonNetwork(org.alfresco.rest.api.model.PersonNetwork) ResponseWriter(org.alfresco.rest.framework.tools.ResponseWriter) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Aggregations

PersonNetwork (org.alfresco.rest.api.model.PersonNetwork)5 Network (org.alfresco.rest.api.model.Network)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayList (java.util.ArrayList)2 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)2 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)2 ResponseWriter (org.alfresco.rest.framework.tools.ResponseWriter)2 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)2 NetworkImpl (org.alfresco.rest.api.model.NetworkImpl)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1