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;
}
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());
}
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;
}
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);
}
}
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);
}
}
Aggregations