use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateConstraintAndAddToProperty.
@Test
public void testCreateConstraintAndAddToProperty() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelConstraint" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Create RegEx constraint
String regExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
CustomModelConstraint regExConstraint = new CustomModelConstraint();
regExConstraint.setName(regExConstraintName);
regExConstraint.setType("REGEX");
regExConstraint.setTitle("test RegEx title");
regExConstraint.setDescription("test RegEx desc");
// Create the RegEx constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("expression", "(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)"));
parameters.add(buildNamedValue("requiresMatch", "false"));
// Add the parameters into the constraint
regExConstraint.setParameters(parameters);
// Create constraint as a Model Administrator
post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201);
// Retrieve the created constraint
HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200);
CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
// Retrieve all the model's constraints
Paging paging = getPaging(0, Integer.MAX_VALUE);
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(1, constraints.size());
// Create aspect
String aspectName = "testAspect1" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the Aspect by adding property
CustomAspect payload = new CustomAspect();
payload.setName(aspectName);
final String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setDataType("d:text");
// Add the constraint ref
aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
// Create the property
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Activate the model
CustomModel updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Retrieve all the model's constraints
// Test to see if the API took care of duplicate constraints when referencing a constraint within a property.
response = getAll("cmm/" + modelName + "/constraints", paging, 200);
constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
assertEquals(1, constraints.size());
// Test RegEx constrain enforcement
{
final NodeService nodeService = repoService.getNodeService();
final QName aspectQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectName);
TestNetwork testNetwork = getTestFixture().getRandomNetwork();
TestPerson person = testNetwork.createUser();
final String siteName = "site" + System.currentTimeMillis();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
TestSite site = repoService.createSite(null, siteInfo);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
nodeService.addAspect(nodeRef, aspectQName, null);
assertTrue(nodeService.hasAspect(nodeRef, aspectQName));
try {
QName propQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectPropName);
nodeService.setProperty(nodeRef, propQName, "Invalid$Char.");
fail("Invalid property value. Should have caused integrity violations.");
} catch (Exception e) {
// Expected
}
// Permanently remove model from repository
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
nodeService.deleteNode(nodeRef);
return null;
}
}, person.getId(), testNetwork.getId());
}
setRequestContext(customModelAdmin);
// Deactivate the model
updatePayload = new CustomModel();
updatePayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
// Test update the namespace prefix (test to see if the API updates the constraints refs with this new prefix)
CustomModel updateModelPayload = new CustomModel();
String modifiedPrefix = namespacePair.getSecond() + "Modified";
updateModelPayload.setNamespacePrefix(modifiedPrefix);
updateModelPayload.setNamespaceUri(namespacePair.getFirst());
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix());
assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri());
// Test update the namespace URI
updateModelPayload = new CustomModel();
updateModelPayload.setNamespacePrefix(modifiedPrefix);
String modifiedURI = namespacePair.getFirst() + "Modified";
updateModelPayload.setNamespaceUri(modifiedURI);
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedURI, returnedModel.getNamespaceUri());
assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestFavourites method setup.
@Override
@Before
public void setup() throws Exception {
// init networks
super.setup();
final Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable {
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// create some users
TestFavourites.this.network1 = networksIt.next();
String name = GUID.generate();
PersonInfo personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
TestFavourites.this.person10 = network1.createUser(personInfo);
assertNotNull(TestFavourites.this.person10);
TestFavourites.this.person10Id = TestFavourites.this.person10.getId();
name = GUID.generate();
personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
TestFavourites.this.person11 = network1.createUser(personInfo);
assertNotNull(TestFavourites.this.person11);
TestFavourites.this.person11Id = TestFavourites.this.person11.getId();
name = GUID.generate();
personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
TestFavourites.this.person12 = network1.createUser(personInfo);
assertNotNull(TestFavourites.this.person12);
TestFavourites.this.person12Id = TestFavourites.this.person12.getId();
name = GUID.generate();
personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
TestFavourites.this.person14 = network1.createUser(personInfo);
assertNotNull(TestFavourites.this.person14);
TestFavourites.this.person14Id = TestFavourites.this.person14.getId();
TestFavourites.this.network2 = networksIt.next();
name = GUID.generate();
personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
TestFavourites.this.person21 = network2.createUser(personInfo);
assertNotNull(TestFavourites.this.person21);
TestFavourites.this.person21Id = TestFavourites.this.person21.getId();
return null;
} finally {
AuthenticationUtil.popAuthentication();
}
}
}, false, true);
// Create some favourite targets, sites, files and folders
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
person1PublicSites.add(site);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
person1PublicDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description");
person1PublicFolders.add(nodeRef);
nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
person1PublicDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description");
person1PublicFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content");
person1PublicDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description");
person1PublicFolders.add(nodeRef);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
person1PublicSites.add(site);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
site = network1.createSite(siteInfo);
person1PrivateSites.add(site);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
person1PrivateDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description");
person1PrivateFolders.add(nodeRef);
nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
person1PrivateDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description");
person1PrivateFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content");
person1PrivateDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description");
person1PrivateFolders.add(nodeRef);
return null;
}
}, person11Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
person1PublicSites.add(site);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
personFolders.add(nodeRef);
return null;
}
}, person10Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
personSites.add(site);
site.inviteToSite(person11Id, SiteRole.SiteCollaborator);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
personSites.add(site);
return null;
}
}, person10Id, network1.getId());
this.favouritesProxy = publicApiClient.favourites();
this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSitesWithSameTitles.
// ACE-4823
@Test
public void testSitesWithSameTitles() throws Exception {
// Creates 3 sites
initializeSites();
final String site4_name = "d_" + GUID.generate();
// Same title as site3
final String site4_title = site3_title;
final SiteRole site4_role = SiteRole.SiteCollaborator;
TestSite site4 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(site4_name, site4_title, site4_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site4_role);
return site;
}
}, person31.getId(), network1.getId());
assertNotNull(site4);
// paging
int totalResults = 4;
Paging paging = getPaging(null, null, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site2, site2_role));
expectedList.add(new MemberOfSite(site3, site3_role));
expectedList.add(new MemberOfSite(site4, site4_role));
expectedList.add(new MemberOfSite(site1, site1_role));
try {
checkList(expectedList, paging.getExpectedPaging(), resp);
} catch (AssertionError error) {
// Site3 and Site4 have a same title, and as we are sorting on titles (default sorting),
// we can't guarantee the order in which the sites will
// return, hence swap the sites and compare again.
Collections.swap(expectedList, 1, 2);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method setup.
@Override
@Before
public void setup() throws Exception {
// init networks
super.setup();
Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
this.network1 = networksIt.next();
Iterator<String> personIt = network1.getPersonIds().iterator();
this.person11Id = personIt.next();
assertNotNull(person11Id);
this.person12Id = personIt.next();
assertNotNull(person12Id);
this.person13Id = personIt.next();
assertNotNull(person13Id);
this.person14Id = personIt.next();
assertNotNull(person14Id);
this.person15Id = personIt.next();
assertNotNull(person15Id);
this.network2 = networksIt.next();
Iterator<String> person1It = network2.getPersonIds().iterator();
this.person24Id = person1It.next();
assertNotNull(person24Id);
// Create some sites, files and folders
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String guid = GUID.generate();
String[] siteNames = new String[] { "sitex" + guid, "sitea" + guid, "sitef" + guid, "site234" + guid, "sitey" + guid, "siteb" + guid, "site643" + guid, "site24" + guid, "site8d6sc" + guid };
String siteName = siteNames[0];
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
TestSite site = network1.createSite(siteInfo);
person1ModeratedSites.add(site);
for (int i = 1; i < siteNames.length; i++) {
siteName = siteNames[i];
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
site = network1.createSite(siteInfo);
person1ModeratedSites.add(site);
}
String[] mixedCaseSiteNames = new String[] { "MixedCase" + guid, "mixedCaseA" + guid };
for (int i = 0; i < mixedCaseSiteNames.length; i++) {
siteName = mixedCaseSiteNames[i];
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
site = network1.createSite(siteInfo);
person1MixedCaseModeratedSites.add(site);
}
for (int i = 0; i < 1; i++) {
siteName = "privatesite" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
site = network1.createSite(siteInfo);
person1PrivateSites.add(site);
}
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
person1Folders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
person1Folders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
person1Folders.add(nodeRef);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
person1PublicSites.add(site);
return null;
}
}, person12Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
personFolders.add(nodeRef);
return null;
}
}, person11Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
personPublicSites.add(site);
site.inviteToSite(person12Id, SiteRole.SiteCollaborator);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
personPublicSites.add(site);
return null;
}
}, person11Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
TestSite site = network1.createSite(siteInfo);
person4ModeratedSites.add(site);
return null;
}
}, person24Id, network2.getId());
this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
}
Aggregations