use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestFavouriteSites method testFavouriteSites.
@Test
public void testFavouriteSites() throws Exception {
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
final TestNetwork network1 = networksIt.next();
assertTrue(networksIt.hasNext());
final TestNetwork network2 = networksIt.next();
// Create some users and sites
final List<TestPerson> people = new ArrayList<TestPerson>();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
final TestPerson person1 = people.get(0);
final TestPerson person2 = people.get(1);
final TestPerson person3 = people.get(2);
final TestPerson person4 = people.get(3);
final TestPerson person5 = people.get(3);
TestSite testSite = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite1 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite3 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
TestSite testSite4 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person5.getId(), network2.getId());
}
}, false, true);
Sites sitesProxy = publicApiClient.sites();
// invalid methods
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.create("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to POST to a favorite-site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.update("people", person1.getId(), "favorite-sites", null, fs.toJSON().toString(), "Unable to PUT favorite-sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.update("people", person1.getId(), "favorite-sites", testSite.getSiteId(), fs.toJSON().toString(), "Unable to PUT a favorite-site");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.remove("people", person1.getId(), "favorite-sites", null, "Unable to DELETE favorite-sites");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// unknown user - 404
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite("invalid.user", fs);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// user from another network - 401 (not able to auth against tenant)
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite(person1.getId(), fs);
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
sitesProxy.createFavouriteSite(person2.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// a member of this site
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
FavouriteSite resp = sitesProxy.createFavouriteSite(person1.getId(), fs);
fs.expected(resp);
}
// add same favourite site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.createFavouriteSite(person1.getId(), new FavouriteSite(testSite.getSiteId()));
fail();
} catch (PublicApiException e) {
assertEquals(409, e.getHttpResponse().getStatusCode());
}
// "-me" user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
FavouriteSite fs = new FavouriteSite(testSite.getSiteId());
FavouriteSite resp = sitesProxy.createFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
fs.expected(resp);
final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person2);
}
}, person2.getId(), network1.getId());
// check it's there
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
sitesProxy.getFavouriteSites(person2.getId(), createParams(paging, null));
}
// not a member of this site
{
FavouriteSite fs = new FavouriteSite(testSite1.getSiteId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite ret = sitesProxy.createFavouriteSite(person1.getId(), fs);
fs.expected(ret);
}
// GET favourite sites
{
final List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person1);
}
}, person1.getId(), network1.getId());
// unknown user
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
sitesProxy.getFavouriteSites(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// authentication: unknown user
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), GUID.generate(), "password"));
sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// another user from the same network - 403
try {
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
}
// another user from another network - 401
try {
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person4.getId()));
sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// successful GET
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
// skipCount is greater than the number of favourite sites
{
int skipCount = expectedFavouriteSites.size() + 100;
Paging paging = getPaging(skipCount, null, expectedFavouriteSites.size(), expectedFavouriteSites.size());
List<FavouriteSite> expected = Collections.emptyList();
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
checkList(expected, paging.getExpectedPaging(), response);
}
// "-me-" user
{
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
}
// user is a member of the site which he has favourited
{
publicApiClient.setRequestContext(new RequestContext(network2.getId(), person5.getId()));
List<FavouriteSite> expectedFavouriteSites = new ArrayList<FavouriteSite>(1);
FavouriteSite fs = new FavouriteSite(testSite4.getSiteId());
expectedFavouriteSites.add(fs);
FavouriteSite ret = sitesProxy.createFavouriteSite(person5.getId(), fs);
fs.expected(ret);
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person5.getId(), createParams(paging, null));
checkList(expectedFavouriteSites, paging.getExpectedPaging(), response);
}
// remove
{
// create some favourite sites
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.createFavouriteSite(person3.getId(), fs);
fs = new FavouriteSite(testSite1);
sitesProxy.createFavouriteSite(person3.getId(), fs);
}
// known user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.removeFavouriteSite(person1.getId(), fs);
List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person1);
}
}, person1.getId(), network1.getId());
// check removed
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person1.getId(), createParams(paging, null));
assertFalse(response.getList().contains(fs));
}
// unknown user
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite);
sitesProxy.removeFavouriteSite(GUID.generate(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// unknown site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(GUID.generate());
sitesProxy.removeFavouriteSite(person1.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// try to remove a favourite site that is not a favourite site
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
FavouriteSite fs = new FavouriteSite(testSite3);
sitesProxy.removeFavouriteSite(person1.getId(), fs);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// "-me-" user
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
FavouriteSite fs = new FavouriteSite(testSite1);
sitesProxy.removeFavouriteSite(org.alfresco.rest.api.People.DEFAULT_USER, fs);
List<FavouriteSite> expectedFavouriteSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<FavouriteSite>>() {
@Override
public List<FavouriteSite> doWork() throws Exception {
return repoService.getFavouriteSites(person3);
}
}, person3.getId(), network1.getId());
// check removed
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedFavouriteSites.size(), expectedFavouriteSites.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
ListResponse<FavouriteSite> response = sitesProxy.getFavouriteSites(person3.getId(), createParams(paging, null));
assertFalse(response.getList().contains(fs));
}
}
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class EnterpriseTestFixture method populateTestData.
@Override
protected void populateTestData() {
for (int i = 1; i <= 2; i++) {
TestNetwork network = repoService.createNetworkWithAlias(TEST_DOMAIN_PREFIX + "00" + i, true);
addNetwork(network);
}
// 5 public sites
for (int i = 0; i < 5; i++) {
SiteInformation siteInfo = new SiteInformation("testSite" + i, "Public Test Site" + i, "Public Test Site" + i, SiteVisibility.PUBLIC);
addSite(siteInfo);
}
// 5 private sites
for (int i = 5; i < 10; i++) {
SiteInformation siteInfo = new SiteInformation("testSite" + i, "Private Test Site" + i, "Private Test Site" + i, SiteVisibility.PRIVATE);
addSite(siteInfo);
}
addPerson(new PersonInfo("David", "Smith", "david.smith", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
addPerson(new PersonInfo("Bob", "Jones", "bob.jones", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
addPerson(new PersonInfo("Bill", "Grainger", "bill.grainger", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
addPerson(new PersonInfo("Jill", "Fry", "jill.fry", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
addPerson(new PersonInfo("Elvis", "Presley", "elvis.presley", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
addPerson(new PersonInfo("John", "Lennon", "john.lennon", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
addPerson(new PersonInfo("George", "Harrison", "george.harrison", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
addPerson(new PersonInfo("David", "Bowie", "david.bowie", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
addPerson(new PersonInfo("Ford", "Prefect", "ford.prefect", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestPersonSites method initializeSites.
// TODO switch to use V1 createSite (instead of RepoService)
private void initializeSites() throws Exception {
/*
* Create data for testing the site sorting. We create the sites as
* person31 and assign roles to person32. The list requests will be
* performed as person32.
*/
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
person31 = network1.createUser();
person32 = network1.createUser();
return null;
}
}, network1.getId());
this.site1 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(site1_id, site1_title, site1_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site1_role);
return site;
}
}, person31.getId(), network1.getId());
this.site2 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(site2_id, site2_title, site2_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site2_role);
return site;
}
}, person31.getId(), network1.getId());
this.site3 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(site3_id, site3_title, site3_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site3_role);
return site;
}
}, person31.getId(), network1.getId());
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class AbstractTestFixture method createTestData.
public void createTestData() {
for (final TestNetwork testAccount : getNetworks().values()) {
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
testAccount.create();
for (PersonInfo testPerson : people) {
testAccount.createUser(testPerson);
}
return null;
}
}, false, true);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable {
// clear fully authenticated user ("admin") - affects site creation (which uses this to setup perms)
AuthenticationUtil.clearCurrentSecurityContext();
if (testAccount.getPersonIds().size() > 0) {
// use a fixed sample size of account members (so we have some left over for tests)
List<String> people = testAccount.peopleSample(testAccount.getPersonIds().size());
String tenantDomain = testAccount.getId();
int i = 0;
for (final SiteInformation site : getSites().values()) {
final Iterator<String> peopleIterator = RepoService.getWrappingIterator(i++, people);
final String siteCreator = peopleIterator.next();
assertNotNull(siteCreator);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
final TestSite testSite = testAccount.createSite(site);
// invite some members to the site, leave at least one non-site member
for (int j = 0; j < numMembersPerSite; j++) {
String siteMember = peopleIterator.next();
assertNotNull(siteMember);
testSite.inviteToSite(siteMember, SiteRole.SiteContributor);
}
return null;
}
}, siteCreator, tenantDomain);
}
}
return null;
}
}, false, true);
}
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestActivities method setup.
@Before
public void setup() throws Exception {
// note: we don't call super.setup() since we create our own test data here !
this.network1 = repoService.createNetworkWithAlias("activitiesNetwork1", true);
this.network2 = repoService.createNetworkWithAlias("activitiesNetwork2", true);
this.defaultNetwork = repoService.createNetwork(TenantService.DEFAULT_DOMAIN, true);
siteService = (SiteService) applicationContext.getBean("SiteService");
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
network1.create();
network2.create();
defaultNetwork.create();
} finally {
AuthenticationUtil.popAuthentication();
}
// Create some users and sites
final List<TestPerson> people = new ArrayList<TestPerson>(5);
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = defaultNetwork.createUser();
people.add(person);
person = defaultNetwork.createUser();
people.add(person);
return null;
}
}, defaultNetwork.getId());
this.person1 = people.get(0);
this.person2 = people.get(1);
this.person3 = people.get(2);
this.person4 = people.get(3);
this.person5 = people.get(4);
this.testSite = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person2.getId(), SiteRole.SiteCollaborator);
return site;
}
}, person1.getId(), network1.getId());
}
}, false, true);
this.testSite1 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network1.createSite(siteInfo);
}
}, person1.getId(), network1.getId());
}
}, false, true);
// create some activities against those sites
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void doWork() throws Exception {
// ensure at least 3 activities
JSONObject activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite1.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite1.getSiteId(), activityData);
return null;
}
}, person1.getId(), network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void doWork() throws Exception {
// ensure at least 3 activities
JSONObject activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
return null;
}
}, person2.getId(), network1.getId());
// user generates activities in 2 networks
this.testSite2 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return network2.createSite(siteInfo);
}
}, person3.getId(), network2.getId());
}
}, false, true);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void doWork() throws Exception {
// ensure at least 3 activities
JSONObject activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite.getSiteId(), activityData);
return null;
}
}, person3.getId(), network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void doWork() throws Exception {
// ensure at least 3 activities
JSONObject activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite2.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite2.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite2.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite2.getSiteId(), activityData);
activityData = new JSONObject();
activityData.put("title", GUID.generate());
activityData.put("nodeRef", testSite2.getContainerNodeRef("documentLibrary").toString());
repoService.postActivity("org.alfresco.documentlibrary.file-added", testSite2.getSiteId(), activityData);
return null;
}
}, person3.getId(), network2.getId());
this.testSite3 = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<TestSite>() {
@SuppressWarnings("synthetic-access")
public TestSite execute() throws Throwable {
return TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(GUID.generate(), "", "", SiteVisibility.PUBLIC);
return defaultNetwork.createSite(siteInfo);
}
}, person4.getId(), defaultNetwork.getId());
}
}, false, true);
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void doWork() throws Exception {
siteService.setMembership(testSite3.getSiteId(), person5.getId(), SiteModel.SITE_CONSUMER);
return null;
}
}, person4.getId(), defaultNetwork.getId());
repoService.generateFeed();
}
Aggregations