use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestPeople method createAvatarDirect.
private NodeRef createAvatarDirect(NodeRef personRef, File avatarFile) {
// create new avatar node
nodeService.addAspect(personRef, ContentModel.ASPECT_PREFERENCES, null);
ChildAssociationRef assoc = nodeService.createNode(personRef, ContentModel.ASSOC_PREFERENCE_IMAGE, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar"), ContentModel.TYPE_CONTENT);
final NodeRef avatarRef = assoc.getChildRef();
// JSF client compatibility?
nodeService.createAssociation(personRef, avatarRef, ContentModel.ASSOC_AVATAR);
// upload the avatar content
ContentService contentService = applicationContext.getBean("ContentService", ContentService.class);
ContentWriter writer = contentService.getWriter(avatarRef, ContentModel.PROP_CONTENT, true);
writer.guessMimetype(avatarFile.getName());
writer.putContent(avatarFile);
Rendition avatarR = new Rendition();
avatarR.setId("avatar");
Renditions renditions = applicationContext.getBean("Renditions", Renditions.class);
renditions.createRendition(avatarRef, avatarR, false, null);
return avatarRef;
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestPeople method createTestUpdatePerson.
// Create a person for use in the testing of updating custom aspects/props
private Person createTestUpdatePerson() throws PublicApiException {
Person person = new Person();
String personId = UUID.randomUUID().toString() + "@" + account1.getId();
person.setUserName(personId);
person.setFirstName("Joe");
person.setEmail(personId);
person.setEnabled(true);
person.setPassword("password123");
person.setDescription("This is a very short bio.");
person.setProperties(Collections.singletonMap("papi:jabber", "jbloggs@example.com"));
person.setAspectNames(Collections.singletonList("papi:dessertable"));
person = people.create(person);
AuthenticationUtil.setFullyAuthenticatedUser("admin@" + account1.getId());
NodeRef nodeRef = personService.getPerson(person.getId());
// Add some non-custom aspects, these should be untouched by the people API.
nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUDITABLE, null);
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "This is a title");
assertEquals("jbloggs@example.com", person.getProperties().get("papi:jabber"));
assertEquals(2, person.getAspectNames().size());
assertTrue(person.getAspectNames().contains("papi:comms"));
assertTrue(person.getAspectNames().contains("papi:dessertable"));
return person;
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestPeople method updateAvatar.
@Test
public void updateAvatar() throws PublicApiException, IOException {
final String person1 = account1PersonIt.next();
final String person2 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person2));
AuthenticationUtil.setFullyAuthenticatedUser(person2);
// Update allowed when no existing avatar
{
// Pre-condition: no avatar exists
NodeRef personRef = personService.getPerson(person2, false);
deleteAvatarDirect(personRef);
people.getAvatar(person2, false, 404);
// TODO: What do we expect the 200 response body to be? Currently it's the person JSON - doesn't seem right.
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
// TODO: ideally, this should be a "direct" retrieval to isolate update from get
people.getAvatar(person2, false, 200);
}
// Update existing avatar
{
// Pre-condition: avatar exists
people.getAvatar(person2, false, 200);
ClassPathResource avatar = new ClassPathResource("test.jpg");
HttpResponse response = people.updateAvatar(person2, avatar.getFile(), 200);
people.getAvatar(person2, false, 200);
// -me- alias
people.updateAvatar(person2, avatar.getFile(), 200);
people.getAvatar("-me-", false, 200);
}
// 400: invalid user ID
{
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar("joe@@bloggs.example.com", avatar.getFile(), 404);
}
// 401: authentication failure
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "Wr0ngP4ssw0rd!"));
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(account1Admin, avatar.getFile(), 401);
}
// 403: permission denied
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person2, avatar.getFile(), 403);
// Person can update themself
people.updateAvatar(person1, avatar.getFile(), 200);
// Admin can update someone else
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
people.updateAvatar(person1, avatar.getFile(), 200);
}
// 404: non-existent person
{
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
// Pre-condition: non-existent person
String nonPerson = "joebloggs@" + account1.getId();
people.getPerson(nonPerson, 404);
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(nonPerson, avatar.getFile(), 404);
}
// 413: content exceeds individual file size limit
{
// Test content size limit
final ContentLimitProvider.SimpleFixedLimitProvider limitProvider = applicationContext.getBean("defaultContentLimitProvider", ContentLimitProvider.SimpleFixedLimitProvider.class);
final long defaultSizeLimit = limitProvider.getSizeLimit();
// 20 KB
limitProvider.setSizeLimitString("20000");
try {
// ~26K
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person1, avatar.getFile(), 413);
} finally {
limitProvider.setSizeLimitString(Long.toString(defaultSizeLimit));
}
}
// 501: thumbnails disabled
{
ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class);
// Disable thumbnail generation
thumbnailService.setThumbnailsEnabled(false);
try {
ClassPathResource avatar = new ClassPathResource("publicapi/upload/quick.jpg");
people.updateAvatar(person1, avatar.getFile(), 501);
} finally {
thumbnailService.setThumbnailsEnabled(true);
}
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestPeople method retrieveAvatar.
@Test
public void retrieveAvatar() throws Exception {
final String person1 = account1PersonIt.next();
publicApiClient.setRequestContext(new RequestContext(account1.getId(), person1));
AuthenticationUtil.setFullyAuthenticatedUser(person1);
NodeRef person1Ref = personService.getPerson(person1, false);
// No avatar, but valid person
{
deleteAvatarDirect(person1Ref);
// Pre-condition of test case
assertNotNull(people.getPerson(person1));
people.getAvatar(person1, false, 404);
}
// No avatar, but person exists and placeholder requested
{
// Pre-condition of test case
assertNotNull(people.getPerson(person1));
people.getAvatar(person1, true, 200);
}
// Non-existent person
{
String nonPerson = "i-do-not-exist";
// Pre-condition of test case
people.getPerson(nonPerson, 404);
people.getAvatar(nonPerson, false, 404);
}
// Placeholder requested, but non-existent person
{
String nonPerson = "i-do-not-exist";
// Pre-condition of test case
people.getPerson(nonPerson, 404);
people.getAvatar(nonPerson, true, 404);
}
// Avatar exists
{
// Create avatar - direct (i.e. not using the API, so that tests for get avatar can be separated from upload)
// There's no significance to the image being used here, it was the most suitable I could find.
ClassPathResource thumbRes = new ClassPathResource("test.jpg");
deleteAvatarDirect(person1Ref);
createAvatarDirect(person1Ref, thumbRes.getFile());
// Get avatar - API call
people.getAvatar(person1, false, 200);
}
// -me- alias
{
people.getAvatar("-me-", false, 200);
}
// If-Modified-Since behaviour
{
HttpResponse response = people.getAvatar(person1, false, 200);
Map<String, String> responseHeaders = response.getHeaders();
// Test 304 response
String lastModified = responseHeaders.get(LAST_MODIFIED_HEADER);
assertNotNull(lastModified);
// Has it been modified since the time it was last modified - no!
people.getAvatar(person1, lastModified, 304);
// Create an updated avatar
// ensure time has passed between updates
waitMillis(2000);
ClassPathResource thumbRes = new ClassPathResource("publicapi/upload/quick.jpg");
deleteAvatarDirect(person1Ref);
createAvatarDirect(person1Ref, thumbRes.getFile());
people.getAvatar(person1, lastModified, 200);
}
// Attachment param
{
// No attachment parameter (default true)
Boolean attachmentParam = null;
HttpResponse response = people.getAvatar(person1, attachmentParam, false, null, 200);
Map<String, String> responseHeaders = response.getHeaders();
String contentDisposition = responseHeaders.get("Content-Disposition");
assertNotNull(contentDisposition);
assertTrue(contentDisposition.startsWith("attachment;"));
// attachment=true
attachmentParam = true;
response = people.getAvatar(person1, attachmentParam, false, null, 200);
responseHeaders = response.getHeaders();
contentDisposition = responseHeaders.get("Content-Disposition");
assertNotNull(contentDisposition);
assertTrue(contentDisposition.startsWith("attachment;"));
// attachment=false
attachmentParam = false;
response = people.getAvatar(person1, attachmentParam, false, null, 200);
responseHeaders = response.getHeaders();
contentDisposition = responseHeaders.get("Content-Disposition");
assertNull(contentDisposition);
}
}
use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.
the class TestSiteContainers method setup.
@Override
@Before
public void setup() throws Exception {
// init networks
super.setup();
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
this.network1 = networksIt.next();
assertTrue(networksIt.hasNext());
this.network2 = networksIt.next();
// Create some users in different networks
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
// add as external user
TestPerson person1 = network1.createUser();
people1.add(person1);
TestPerson person2 = network1.createUser();
people1.add(person2);
TestPerson person3 = network1.createUser();
people1.add(person3);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person1 = network2.createUser();
people2.add(person1);
return null;
}
}, network2.getId());
// site creator
this.person11 = people1.get(0);
// same network, not invited to site
this.person12 = people1.get(1);
// different network, not invited to site
this.person21 = people2.get(0);
// same network, invited to site
this.person13 = people1.get(2);
// TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
// {
// @Override
// public Void doWork() throws Exception
// {
// // add as external user
// TestPerson person1 = network2.createUser();
// network2People.add(person1);
//
// return null;
// }
// }, network2.getId());
//
// final TestPerson person3 = network2People.get(0);
// Create a public site
this.site1 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite testSite = network1.createSite(SiteVisibility.PUBLIC);
return testSite;
}
}, person11.getId(), network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Map<String, NodeRef>>() {
@Override
public Map<String, NodeRef> doWork() throws Exception {
Map<String, NodeRef> containers = new HashMap<String, NodeRef>();
containers.put("test1", site1.createContainer("test1"));
containers.put("test2", site1.createContainer("test2"));
containers.put("test3", site1.createContainer("test3"));
return containers;
}
}, person11.getId(), network1.getId());
}
Aggregations