|
|
@@ -19,22 +19,28 @@
|
|
|
|
package org.alfresco.repo.web.scripts.invitation;
|
|
|
|
package org.alfresco.repo.web.scripts.invitation;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
|
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
|
|
|
import org.alfresco.repo.action.executer.TestModeable;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
|
|
import org.alfresco.repo.site.SiteModel;
|
|
|
|
import org.alfresco.repo.site.SiteModel;
|
|
|
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
|
|
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
|
|
|
|
|
|
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
|
|
|
|
|
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
|
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
|
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
|
|
import org.alfresco.service.cmr.security.PersonService;
|
|
|
|
import org.alfresco.service.cmr.security.PersonService;
|
|
|
|
import org.alfresco.service.cmr.site.SiteService;
|
|
|
|
|
|
|
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
|
|
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
|
|
|
|
|
|
|
import org.alfresco.service.namespace.NamespaceService;
|
|
|
|
|
|
|
|
import org.alfresco.service.namespace.QName;
|
|
|
|
import org.alfresco.util.GUID;
|
|
|
|
import org.alfresco.util.GUID;
|
|
|
|
import org.alfresco.util.PropertyMap;
|
|
|
|
import org.alfresco.util.PropertyMap;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
|
|
|
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
|
|
|
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
|
|
|
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
|
|
@@ -49,144 +55,166 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
|
|
|
* @author Mark Rogers
|
|
|
|
* @author Mark Rogers
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class InvitationTest extends BaseWebScriptTest
|
|
|
|
public class InvitationTest extends BaseWebScriptTest
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private final static QName avatarQName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
|
|
|
|
|
|
|
|
|
|
|
|
private MutableAuthenticationService authenticationService;
|
|
|
|
private MutableAuthenticationService authenticationService;
|
|
|
|
private AuthenticationComponent authenticationComponent;
|
|
|
|
private AuthenticationComponent authenticationComponent;
|
|
|
|
private PersonService personService;
|
|
|
|
private PersonService personService;
|
|
|
|
private SiteService siteService;
|
|
|
|
|
|
|
|
private NodeService nodeService;
|
|
|
|
private NodeService nodeService;
|
|
|
|
|
|
|
|
|
|
|
|
private static final String USER_ONE = "InvitationTestOne";
|
|
|
|
private String userOne = "InvitationTestOne" + GUID.generate();
|
|
|
|
private static final String USER_TWO = "InvitationTestTwo";
|
|
|
|
private String userTwo = "InvitationTestTwo" + GUID.generate();
|
|
|
|
private static final String USER_THREE = "InvitationTestThree";
|
|
|
|
private String userThree = "InvitationTestThree" + GUID.generate();
|
|
|
|
|
|
|
|
|
|
|
|
private static final String URL_SITES = "/api/sites";
|
|
|
|
private static final String URL_SITES = "/api/sites";
|
|
|
|
private static final String URL_INVITATIONS = "/api/invitations";
|
|
|
|
private static final String URL_INVITATIONS = "/api/invitations";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> createdSites = new ArrayList<String>(5);
|
|
|
|
private List<String> createdSites = new ArrayList<String>(5);
|
|
|
|
private List<Tracker> createdInvitations = new ArrayList<Tracker>(10);
|
|
|
|
private List<Tracker> createdInvitations = new ArrayList<Tracker>(10);
|
|
|
|
|
|
|
|
private TestModeable mailActionExecutor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Map<String, String>> userProperties = new HashMap<String, Map<String,String>>(3);
|
|
|
|
|
|
|
|
|
|
|
|
private class Tracker
|
|
|
|
private class Tracker
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public Tracker(String inviteId, String siteName)
|
|
|
|
public Tracker(String inviteId, String siteName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.inviteId = inviteId;
|
|
|
|
this.inviteId = inviteId;
|
|
|
|
this.siteName = siteName;
|
|
|
|
this.siteName = siteName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public String inviteId;
|
|
|
|
|
|
|
|
public String siteName;
|
|
|
|
public String inviteId;
|
|
|
|
|
|
|
|
public String siteName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception
|
|
|
|
protected void setUp() throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super.setUp();
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
|
|
|
|
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
|
|
|
this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean(
|
|
|
|
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
|
|
|
"AuthenticationService");
|
|
|
|
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
|
|
|
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean(
|
|
|
|
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
|
|
|
"authenticationComponent");
|
|
|
|
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
|
|
|
this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
|
|
|
|
|
|
|
|
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
|
|
|
|
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors during unit testing
|
|
|
|
|
|
|
|
|
|
|
|
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
|
|
|
|
|
|
|
|
// during unit testing
|
|
|
|
// (or sending out email by accident from tests)
|
|
|
|
// (or sending out email by accident from tests)
|
|
|
|
MailActionExecuter mail = (MailActionExecuter) getServer().getApplicationContext().getBean("mail");
|
|
|
|
mailActionExecutor = (TestModeable) getServer().getApplicationContext().getBean("mail");
|
|
|
|
mail.setTestMode(true);
|
|
|
|
mailActionExecutor.setTestMode(true);
|
|
|
|
|
|
|
|
|
|
|
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
|
|
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
|
|
|
|
|
|
|
|
|
|
|
// Create users
|
|
|
|
// Create users
|
|
|
|
createUser(USER_ONE);
|
|
|
|
createUser(userOne, "Joe", "Bloggs");
|
|
|
|
createUser(USER_TWO);
|
|
|
|
createUser(userTwo, "Jane", "Doe");
|
|
|
|
createUser(USER_THREE);
|
|
|
|
createUser(userThree, "Nick", "Smith");
|
|
|
|
|
|
|
|
|
|
|
|
// Do tests as user one
|
|
|
|
// Do tests as user one
|
|
|
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
|
|
|
this.authenticationComponent.setCurrentUser(userOne);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void createUser(String userName)
|
|
|
|
private void createUser(String userName, String firstName, String lastName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.authenticationService.authenticationExists(userName) == false)
|
|
|
|
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
|
|
|
{
|
|
|
|
PropertyMap ppOne = new PropertyMap(5);
|
|
|
|
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
|
|
|
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
|
|
|
|
|
|
|
ppOne.put(ContentModel.PROP_FIRSTNAME, firstName);
|
|
|
|
PropertyMap ppOne = new PropertyMap(4);
|
|
|
|
ppOne.put(ContentModel.PROP_LASTNAME, lastName);
|
|
|
|
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
|
|
|
String email = firstName+"@email.com";
|
|
|
|
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
|
|
|
ppOne.put(ContentModel.PROP_EMAIL, email);
|
|
|
|
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
|
|
|
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
|
|
|
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
|
|
|
NodeRef person = personService.createPerson(ppOne);
|
|
|
|
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
|
|
|
String avatarUrl = makeAvatar(person);
|
|
|
|
|
|
|
|
|
|
|
|
this.personService.createPerson(ppOne);
|
|
|
|
// Create expected user properties
|
|
|
|
}
|
|
|
|
HashMap<String, String> properties = new HashMap<String, String>(4);
|
|
|
|
|
|
|
|
properties.put("firstName", firstName);
|
|
|
|
|
|
|
|
properties.put("lastName", lastName);
|
|
|
|
|
|
|
|
properties.put("email", email);
|
|
|
|
|
|
|
|
properties.put("avatar", avatarUrl);
|
|
|
|
|
|
|
|
userProperties.put(userName, properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void tearDown() throws Exception
|
|
|
|
protected void tearDown() throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
super.tearDown();
|
|
|
|
super.tearDown();
|
|
|
|
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
|
|
|
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
|
|
|
|
|
|
|
|
|
|
|
// Tidy-up any site's create during the execution of the test
|
|
|
|
// Tidy-up any site's created during the execution of the test
|
|
|
|
for (String shortName : this.createdSites)
|
|
|
|
for (String shortName : this.createdSites)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 0);
|
|
|
|
sendRequest(new DeleteRequest(URL_SITES + "/" + shortName), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Clear the list
|
|
|
|
// Clear the list
|
|
|
|
this.createdSites.clear();
|
|
|
|
this.createdSites.clear();
|
|
|
|
|
|
|
|
|
|
|
|
for (Tracker invite : this.createdInvitations)
|
|
|
|
for (Tracker invite : this.createdInvitations)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendRequest(new DeleteRequest(URL_SITES + "/" + invite.siteName + "/invitations/" + invite.inviteId), 0);
|
|
|
|
sendRequest(new DeleteRequest(URL_SITES + "/" + invite.siteName + "/invitations/" + invite.inviteId), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Clear the list
|
|
|
|
// Clear the list
|
|
|
|
this.createdSites.clear();
|
|
|
|
this.createdInvitations.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Switch the MailActionExecutor back to normal mode.
|
|
|
|
|
|
|
|
mailActionExecutor.setTestMode(false);
|
|
|
|
|
|
|
|
personService.deletePerson(userOne);
|
|
|
|
|
|
|
|
personService.deletePerson(userTwo);
|
|
|
|
|
|
|
|
personService.deletePerson(userThree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject createSite(String sitePreset, String shortName, String title, String description, SiteVisibility visibility, int expectedStatus)
|
|
|
|
private JSONObject createSite(String sitePreset, String shortName, String title, String description,
|
|
|
|
throws Exception
|
|
|
|
SiteVisibility visibility, int expectedStatus) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JSONObject site = new JSONObject();
|
|
|
|
JSONObject site = new JSONObject();
|
|
|
|
site.put("sitePreset", sitePreset);
|
|
|
|
site.put("sitePreset", sitePreset);
|
|
|
|
site.put("shortName", shortName);
|
|
|
|
site.put("shortName", shortName);
|
|
|
|
site.put("title", title);
|
|
|
|
site.put("title", title);
|
|
|
|
site.put("description", description);
|
|
|
|
site.put("description", description);
|
|
|
|
site.put("visibility", visibility.toString());
|
|
|
|
site.put("visibility", visibility.toString());
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES, site.toString(), "application/json"), expectedStatus);
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES, site.toString(), "application/json"), expectedStatus);
|
|
|
|
this.createdSites.add(shortName);
|
|
|
|
this.createdSites.add(shortName);
|
|
|
|
return new JSONObject(response.getContentAsString());
|
|
|
|
return new JSONObject(response.getContentAsString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Detailed Test of List Invitation Web Script.
|
|
|
|
* Detailed Test of List Invitation Web Script.
|
|
|
|
|
|
|
|
* Using URL: /api/invitations
|
|
|
|
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void testListInvitation() throws Exception
|
|
|
|
public void testInvitationsGet() throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Create two sites.
|
|
|
|
// Create two sites.
|
|
|
|
String shortNameSiteA = GUID.generate();
|
|
|
|
String shortNameSiteA = GUID.generate();
|
|
|
|
createSite("myPreset", shortNameSiteA, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
createSite("myPreset", shortNameSiteA, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
|
|
|
|
|
|
|
|
String shortNameSiteB = GUID.generate();
|
|
|
|
String shortNameSiteB = GUID.generate();
|
|
|
|
createSite("myPreset", shortNameSiteB, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
createSite("myPreset", shortNameSiteB, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteA, USER_TWO
|
|
|
|
// Create a moderated invitation on SiteA, USER_TWO
|
|
|
|
String inviteeComments = "Please sir, let $* me in";
|
|
|
|
String inviteeComments = "Please sir, let $* me in";
|
|
|
|
String userName = USER_TWO;
|
|
|
|
String userName = userTwo;
|
|
|
|
String roleName = SiteModel.SITE_CONSUMER;
|
|
|
|
String roleName = SiteModel.SITE_CONSUMER;
|
|
|
|
String moderatedIdAUSER_TWO = createModeratedInvitation(shortNameSiteA, inviteeComments, userName, roleName);
|
|
|
|
String moderatedIdAUSER_TWO = createModeratedInvitation(shortNameSiteA, inviteeComments, userName, roleName);
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteB, USER_TWO
|
|
|
|
// Create a moderated invitation on SiteB, USER_TWO
|
|
|
|
String moderatedIdBUSER_TWO = createModeratedInvitation(shortNameSiteB, inviteeComments, userName, roleName);
|
|
|
|
String moderatedIdBUSER_TWO = createModeratedInvitation(shortNameSiteB, inviteeComments, userName, roleName);
|
|
|
|
|
|
|
|
|
|
|
|
String inviteeCommentsB = "Please sir, let $* me in";
|
|
|
|
String inviteeCommentsB = "Please sir, let $* me in";
|
|
|
|
String userNameB = USER_THREE;
|
|
|
|
String userNameB = userThree;
|
|
|
|
String roleNameB = SiteModel.SITE_CONSUMER;
|
|
|
|
String roleNameB = SiteModel.SITE_CONSUMER;
|
|
|
|
String moderatedIdBUSER_THREE = createModeratedInvitation(shortNameSiteA, inviteeCommentsB, userNameB, roleNameB);
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteB, USER_THREE
|
|
|
|
|
|
|
|
String moderatedIdBUSER_THREE = createModeratedInvitation(shortNameSiteB, inviteeCommentsB, userNameB,
|
|
|
|
|
|
|
|
roleNameB);
|
|
|
|
|
|
|
|
|
|
|
|
String inviteeFirstName = "Buffy";
|
|
|
|
String inviteeFirstName = "Buffy";
|
|
|
|
String inviteeLastName = "Summers";
|
|
|
|
String inviteeLastName = "Summers";
|
|
|
|
String inviteeEmail = "buffy@sunnydale";
|
|
|
|
String inviteeEmail = "buffy@sunnydale";
|
|
|
@@ -194,141 +222,307 @@ public class InvitationTest extends BaseWebScriptTest
|
|
|
|
String serverPath = "http://localhost:8081/share/";
|
|
|
|
String serverPath = "http://localhost:8081/share/";
|
|
|
|
String acceptURL = "page/accept-invite";
|
|
|
|
String acceptURL = "page/accept-invite";
|
|
|
|
String rejectURL = "page/reject-invite";
|
|
|
|
String rejectURL = "page/reject-invite";
|
|
|
|
|
|
|
|
|
|
|
|
// Create a nominated invitation
|
|
|
|
|
|
|
|
String nominatedId = createNominatedInvitation(shortNameSiteA, inviteeFirstName, inviteeLastName, inviteeEmail, inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* search by user - find USER_TWO's three invitations
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?inviteeUserName=" + USER_TWO), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
//System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject first = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", first);
|
|
|
|
|
|
|
|
JSONObject second = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("second is null", second);
|
|
|
|
|
|
|
|
JSONObject third = getInvitation(nominatedId, data);
|
|
|
|
|
|
|
|
assertNotNull("third is null", third);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < data.length(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
JSONObject obj = data.getJSONObject(i);
|
|
|
|
|
|
|
|
assertEquals("userid is wrong", obj.getString("inviteeUserName"), USER_TWO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* search by type - should find three moderated invitations
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a nominated invitation on SiteA, UsER_TWO
|
|
|
|
|
|
|
|
String nominatedId = createNominatedInvitation(shortNameSiteA, inviteeFirstName, inviteeLastName, inviteeEmail,
|
|
|
|
|
|
|
|
inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search by user - find USER_TWO's three invitations
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED"), 200);
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?inviteeUserName=" + userTwo), 200);
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
//System.out.println(response.getContentAsString());
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
for(int i = 0; i < data.length(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
JSONObject moderatedAInv = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
JSONObject obj = data.getJSONObject(i);
|
|
|
|
assertNotNull("Moderated invitation to Site A not present!", moderatedAInv);
|
|
|
|
assertEquals("invitation type ", obj.getString("invitationType"), "MODERATED");
|
|
|
|
JSONObject moderatedBInv = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
}
|
|
|
|
assertNotNull("Moderated invitation to Site B not present!", moderatedBInv);
|
|
|
|
JSONObject first = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
JSONObject nominatedInv = getInvitation(nominatedId, data);
|
|
|
|
assertNotNull("first is null", first);
|
|
|
|
assertNotNull("Nominated invitation to Site A not present!", nominatedInv);
|
|
|
|
JSONObject second = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("second is null", second);
|
|
|
|
checkJSONInvitations(data);
|
|
|
|
JSONObject third = getInvitation(moderatedIdBUSER_THREE, data);
|
|
|
|
|
|
|
|
assertNotNull("third is null", third);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// search by type - should find three moderated invitations
|
|
|
|
* Search by type and site
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName="+shortNameSiteA+ "&resourceType=WEB_SITE"), 200);
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED"), 200);
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
System.out.println(response.getContentAsString());
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
assertEquals("two moderated invitations not found", data.length(), 2);
|
|
|
|
for (int i = 0; i < data.length(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
JSONObject obj = data.getJSONObject(i);
|
|
|
|
|
|
|
|
assertEquals("Wrong invitation type", "MODERATED", obj.getString("invitationType"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject moderatedATwoInv = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", moderatedATwoInv);
|
|
|
|
|
|
|
|
JSONObject moderatedBTwoInv = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("second is null", moderatedBTwoInv);
|
|
|
|
|
|
|
|
JSONObject moderatedBThreeInv = getInvitation(moderatedIdBUSER_THREE, data);
|
|
|
|
|
|
|
|
assertNotNull("third is null", moderatedBThreeInv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Search by type and site
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName="
|
|
|
|
|
|
|
|
+ shortNameSiteA + "&resourceType=WEB_SITE"), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals("One moderated invitations not found", 1, data.length());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// negative test - unknown resourceType
|
|
|
|
// negative test - unknown resourceType
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName="+shortNameSiteA+ "&resourceType=crap"), 500);
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName="
|
|
|
|
|
|
|
|
+ shortNameSiteA + "&resourceType=madeUpStuff"), 500);
|
|
|
|
|
|
|
|
assertEquals(500, response.getStatus());
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
assertNotNull(top.getString("message"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Detailed Test of List Invitation Web Script.
|
|
|
|
|
|
|
|
* Using URL: /api/sites/{shortname}/invitations
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void testSiteInvitationsGet() throws Exception
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Create two sites.
|
|
|
|
|
|
|
|
String shortNameSiteA = GUID.generate();
|
|
|
|
|
|
|
|
createSite("myPreset", shortNameSiteA, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String shortNameSiteB = GUID.generate();
|
|
|
|
|
|
|
|
createSite("myPreset", shortNameSiteB, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteA, USER_TWO
|
|
|
|
|
|
|
|
String inviteeComments = "Please sir, let $* me in";
|
|
|
|
|
|
|
|
String userName = userTwo;
|
|
|
|
|
|
|
|
String roleName = SiteModel.SITE_CONSUMER;
|
|
|
|
|
|
|
|
String moderatedIdAUSER_TWO = createModeratedInvitation(shortNameSiteA, inviteeComments, userName, roleName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteB, USER_TWO
|
|
|
|
|
|
|
|
String moderatedIdBUSER_TWO = createModeratedInvitation(shortNameSiteB, inviteeComments, userName, roleName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String inviteeCommentsB = "Please sir, let $* me in";
|
|
|
|
|
|
|
|
String userNameB = userThree;
|
|
|
|
|
|
|
|
String roleNameB = SiteModel.SITE_CONSUMER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a moderated invitation on SiteB, USER_THREE
|
|
|
|
|
|
|
|
String moderatedIdBUSER_THREE = createModeratedInvitation(shortNameSiteB, inviteeCommentsB, userNameB,
|
|
|
|
|
|
|
|
roleNameB);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String inviteeFirstName = "Buffy";
|
|
|
|
|
|
|
|
String inviteeLastName = "Summers";
|
|
|
|
|
|
|
|
String inviteeEmail = "buffy@sunnydale";
|
|
|
|
|
|
|
|
String inviteeUserName = userName;
|
|
|
|
|
|
|
|
String serverPath = "http://localhost:8081/share/";
|
|
|
|
|
|
|
|
String acceptURL = "page/accept-invite";
|
|
|
|
|
|
|
|
String rejectURL = "page/reject-invite";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a nominated invitation on SiteA, UsER_TWO
|
|
|
|
|
|
|
|
String nominatedId = createNominatedInvitation(shortNameSiteA, inviteeFirstName, inviteeLastName, inviteeEmail,
|
|
|
|
|
|
|
|
inviteeUserName, roleName, serverPath, acceptURL, rejectURL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search for all invitations to site A: One Moderated Usr2, One Nominated User2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String allSiteAUrl = URL_SITES +"/" + shortNameSiteA + "/invitations";
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(allSiteAUrl), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals("Wrong number of invitations!", 2, data.length());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject moderatedAInv = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("Moderated invitation to Site A not present!", moderatedAInv);
|
|
|
|
|
|
|
|
JSONObject nominatedInv = getInvitation(nominatedId, data);
|
|
|
|
|
|
|
|
assertNotNull("Nominated invitation to Site A not present!", nominatedInv);
|
|
|
|
|
|
|
|
checkJSONInvitations(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search for all invitations to site B: One Moderated User2, One Moderated User3.
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String allSiteBUrl = URL_SITES +"/" + shortNameSiteB + "/invitations";
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(allSiteBUrl), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals("Wrong number of invitations!", 2, data.length());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject moderatedB2Inv = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("Moderated invitation User 2 to Site B not present!", moderatedB2Inv);
|
|
|
|
|
|
|
|
JSONObject moderatedB3Inv = getInvitation(moderatedIdBUSER_THREE, data);
|
|
|
|
|
|
|
|
assertNotNull("Moderated invitation User 3 to Site B not present!", moderatedB3Inv);
|
|
|
|
|
|
|
|
checkJSONInvitations(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search SiteA by type Moderated: One Moderated User2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String siteAModeratedUrl = URL_SITES + "/" +shortNameSiteA + "/invitations?invitationType=MODERATED";
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(siteAModeratedUrl), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals(1, data.length());
|
|
|
|
|
|
|
|
JSONObject invitation = data.getJSONObject(0);
|
|
|
|
|
|
|
|
assertEquals("Wrong invitation type", "MODERATED", invitation.getString("invitationType"));
|
|
|
|
|
|
|
|
JSONObject moderatedATwoInv = getInvitation(moderatedIdAUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", moderatedATwoInv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search SiteA by type Nominated: One Nominated User2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String siteANominatedUrl = URL_SITES + "/" +shortNameSiteA + "/invitations?invitationType=NOMINATED";
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(siteANominatedUrl), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals(1, data.length());
|
|
|
|
|
|
|
|
JSONObject invitation = data.getJSONObject(0);
|
|
|
|
|
|
|
|
assertEquals("Wrong invitation type", "NOMINATED", invitation.getString("invitationType"));
|
|
|
|
|
|
|
|
JSONObject nominatedATwoInv = getInvitation(nominatedId, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", nominatedATwoInv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search SiteB by userId 2: One Moderated User2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String siteBUser2Url = URL_SITES + "/" +shortNameSiteB + "/invitations?inviteeUserName=" + userTwo;
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(siteBUser2Url), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals(1, data.length());
|
|
|
|
|
|
|
|
JSONObject invitation = data.getJSONObject(0);
|
|
|
|
|
|
|
|
assertEquals("Wrong invitation user", userTwo, invitation.getString("inviteeUserName"));
|
|
|
|
|
|
|
|
JSONObject moderatedBTwoInv = getInvitation(moderatedIdBUSER_TWO, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", moderatedBTwoInv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// search SiteB by userId 2: One Moderated User2
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String siteBUser2Url = URL_SITES + "/" +shortNameSiteB + "/invitations?inviteeUserName=" + userThree;
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(siteBUser2Url), 200);
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
// System.out.println(response.getContentAsString());
|
|
|
|
|
|
|
|
JSONArray data = top.getJSONArray("data");
|
|
|
|
|
|
|
|
assertEquals(1, data.length());
|
|
|
|
|
|
|
|
JSONObject invitation = data.getJSONObject(0);
|
|
|
|
|
|
|
|
assertEquals("Wrong invitation user", userThree, invitation.getString("inviteeUserName"));
|
|
|
|
|
|
|
|
JSONObject moderatedBThreeInv = getInvitation(moderatedIdBUSER_THREE, data);
|
|
|
|
|
|
|
|
assertNotNull("first is null", moderatedBThreeInv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// negative test - unknown resourceType
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Response response = sendRequest(new GetRequest(URL_INVITATIONS + "?invitationType=MODERATED&resourceName="
|
|
|
|
|
|
|
|
+ shortNameSiteA + "&resourceType=madeUpStuff"), 500);
|
|
|
|
|
|
|
|
assertEquals(500, response.getStatus());
|
|
|
|
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
|
|
|
|
assertNotNull(top.getString("message"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkJSONInvitations(JSONArray data) throws JSONException
|
|
|
|
private String createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName, String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath, String acceptURL, String rejectURL) throws Exception
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int i = 0; i < data.length(); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
JSONObject invitation = data.getJSONObject(i);
|
|
|
|
|
|
|
|
String userId = invitation.getString("inviteeUserName");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check invitee info for Nominated invitation.
|
|
|
|
|
|
|
|
Map<String, String> expectedProps = userProperties.get(userId);
|
|
|
|
|
|
|
|
JSONObject invitee = invitation.getJSONObject("invitee");
|
|
|
|
|
|
|
|
assertNotNull(invitee);
|
|
|
|
|
|
|
|
assertEquals("User name is wrong for user: " + i, userId, invitee.getString("userName"));
|
|
|
|
|
|
|
|
assertEquals("Avatar URI is wrong for user: " + i, expectedProps.get("avatar"), invitee.getString("avatar"));
|
|
|
|
|
|
|
|
assertEquals("First name is wrong!", expectedProps.get("firstName"), invitee.getString("firstName"));
|
|
|
|
|
|
|
|
assertEquals("Last name is wrong!", expectedProps.get("lastName"), invitee.getString("lastName"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String makeAvatar(final NodeRef person)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nodeService.addAspect(person, ContentModel.ASPECT_PREFERENCES, null);
|
|
|
|
|
|
|
|
ChildAssociationRef assoc = nodeService.createNode(person, ContentModel.ASSOC_PREFERENCE_IMAGE, avatarQName,
|
|
|
|
|
|
|
|
ContentModel.TYPE_CONTENT);
|
|
|
|
|
|
|
|
NodeRef avatar = assoc.getChildRef();
|
|
|
|
|
|
|
|
nodeService.createAssociation(person, avatar, ContentModel.ASSOC_AVATAR);
|
|
|
|
|
|
|
|
return "api/node/" + avatar + "/content/thumbnails/avatar";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String createNominatedInvitation(String siteName, String inviteeFirstName, String inviteeLastName,
|
|
|
|
|
|
|
|
String inviteeEmail, String inviteeUserName, String inviteeRoleName, String serverPath,
|
|
|
|
|
|
|
|
String acceptURL, String rejectURL) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Create a new nominated invitation
|
|
|
|
* Create a new nominated invitation
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
JSONObject newInvitation = new JSONObject();
|
|
|
|
JSONObject newInvitation = new JSONObject();
|
|
|
|
|
|
|
|
|
|
|
|
newInvitation.put("invitationType", "NOMINATED");
|
|
|
|
newInvitation.put("invitationType", "NOMINATED");
|
|
|
|
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
|
|
|
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
|
|
|
if(inviteeUserName != null)
|
|
|
|
if (inviteeUserName != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// nominate an existing user
|
|
|
|
// nominate an existing user
|
|
|
|
newInvitation.put("inviteeUserName", inviteeUserName);
|
|
|
|
newInvitation.put("inviteeUserName", inviteeUserName);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// nominate someone else
|
|
|
|
// nominate someone else
|
|
|
|
newInvitation.put("inviteeFirstName", inviteeFirstName);
|
|
|
|
newInvitation.put("inviteeFirstName", inviteeFirstName);
|
|
|
|
newInvitation.put("inviteeLastName", inviteeLastName);
|
|
|
|
newInvitation.put("inviteeLastName", inviteeLastName);
|
|
|
|
newInvitation.put("inviteeEmail", inviteeEmail);
|
|
|
|
newInvitation.put("inviteeEmail", inviteeEmail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newInvitation.put("serverPath", serverPath);
|
|
|
|
newInvitation.put("serverPath", serverPath);
|
|
|
|
newInvitation.put("acceptURL", acceptURL);
|
|
|
|
newInvitation.put("acceptURL", acceptURL);
|
|
|
|
newInvitation.put("rejectURL", rejectURL);
|
|
|
|
newInvitation.put("rejectURL", rejectURL);
|
|
|
|
|
|
|
|
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation
|
|
|
|
|
|
|
|
.toString(), "application/json"), 201);
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject data = top.getJSONObject("data");
|
|
|
|
JSONObject data = top.getJSONObject("data");
|
|
|
|
String inviteId = data.getString("inviteId");
|
|
|
|
String inviteId = data.getString("inviteId");
|
|
|
|
|
|
|
|
|
|
|
|
createdInvitations.add(new Tracker(inviteId, siteName));
|
|
|
|
createdInvitations.add(new Tracker(inviteId, siteName));
|
|
|
|
|
|
|
|
|
|
|
|
return inviteId;
|
|
|
|
return inviteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName, String inviteeRoleName) throws Exception
|
|
|
|
private String createModeratedInvitation(String siteName, String inviteeComments, String inviteeUserName,
|
|
|
|
|
|
|
|
String inviteeRoleName) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Create a new moderated invitation
|
|
|
|
* Create a new moderated invitation
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
JSONObject newInvitation = new JSONObject();
|
|
|
|
JSONObject newInvitation = new JSONObject();
|
|
|
|
|
|
|
|
|
|
|
|
newInvitation.put("invitationType", "MODERATED");
|
|
|
|
newInvitation.put("invitationType", "MODERATED");
|
|
|
|
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
|
|
|
newInvitation.put("inviteeRoleName", inviteeRoleName);
|
|
|
|
newInvitation.put("inviteeComments", inviteeComments);
|
|
|
|
newInvitation.put("inviteeComments", inviteeComments);
|
|
|
|
newInvitation.put("inviteeUserName", inviteeUserName);
|
|
|
|
newInvitation.put("inviteeUserName", inviteeUserName);
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation.toString(), "application/json"), 201);
|
|
|
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + siteName + "/invitations", newInvitation
|
|
|
|
|
|
|
|
.toString(), "application/json"), 201);
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject top = new JSONObject(response.getContentAsString());
|
|
|
|
JSONObject data = top.getJSONObject("data");
|
|
|
|
JSONObject data = top.getJSONObject("data");
|
|
|
|
String inviteId = data.getString("inviteId");
|
|
|
|
String inviteId = data.getString("inviteId");
|
|
|
|
|
|
|
|
|
|
|
|
createdInvitations.add(new Tracker(inviteId, siteName));
|
|
|
|
createdInvitations.add(new Tracker(inviteId, siteName));
|
|
|
|
|
|
|
|
|
|
|
|
return inviteId;
|
|
|
|
return inviteId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject getInvitation(String inviteId, JSONArray data) throws Exception
|
|
|
|
private JSONObject getInvitation(String inviteId, JSONArray data) throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(int i = 0; i < data.length(); i++)
|
|
|
|
for (int i = 0; i < data.length(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
JSONObject obj = data.getJSONObject(i);
|
|
|
|
JSONObject obj = data.getJSONObject(i);
|
|
|
|
if(inviteId.equals(obj.getString("inviteId")))
|
|
|
|
if (inviteId.equals(obj.getString("inviteId")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return obj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|