ACS-9023 Implement PUT method - Preferences API (#3075)

* ACS-9023 Implement PUT method - Preferences API

* ACS-9023 Fix testUserPreferences

* ACS-9023 Add override

* ACS-9023 Update license header
This commit is contained in:
Damian Ujma
2024-12-10 09:51:56 +01:00
committed by GitHub
parent c7bbb1f74b
commit 5a1c8334c8
9 changed files with 3872 additions and 3764 deletions

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* alfresco-tas-restapi * alfresco-tas-restapi
* %% * %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -29,6 +29,12 @@ import static io.restassured.RestAssured.given;
import java.io.File; import java.io.File;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.ValidatableResponse;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.alfresco.rest.core.JsonBodyGenerator; import org.alfresco.rest.core.JsonBodyGenerator;
import org.alfresco.rest.core.RestRequest; import org.alfresco.rest.core.RestRequest;
import org.alfresco.rest.core.RestResponse; import org.alfresco.rest.core.RestResponse;
@@ -56,12 +62,6 @@ import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel; import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.ValidatableResponse;
/** /**
* Declares all Rest API under the /people path * Declares all Rest API under the /people path
@@ -97,9 +97,7 @@ public class People extends ModelRequest<People>
} }
/** /**
* Retrieve list of activities for a specific person using GET call on "people/{personId}/activities" * Retrieve list of activities for a specific person using GET call on "people/{personId}/activities" Please note that it retries to get the list of activities several times before returning the empty list. The list of activities are not displayed as they are created.
* Please note that it retries to get the list of activities several times before returning the empty list. The list of activities are not displayed as
* they are created.
*/ */
public RestActivityModelsCollection getPersonActivitiesUntilEntriesCountIs(int expectedNoOfEntries) public RestActivityModelsCollection getPersonActivitiesUntilEntriesCountIs(int expectedNoOfEntries)
{ {
@@ -173,6 +171,15 @@ public class People extends ModelRequest<People>
return restWrapper.processModel(RestPreferenceModel.class, request); return restWrapper.processModel(RestPreferenceModel.class, request);
} }
/**
* Updates a specific preference of a specific person using PUT call on "people/{personId}/preferences/{preferenceName}"
*/
public RestPreferenceModel updatePersonPreferenceInformation(String preferenceName, RestPreferenceModel preferenceModel)
{
RestRequest request = RestRequest.requestWithBody(HttpMethod.PUT, preferenceModel.toJson(), "people/{personId}/preferences/{preferenceName}", this.person.getUsername(), preferenceName);
return restWrapper.processModel(RestPreferenceModel.class, request);
}
/** /**
* Remove a specific site from favorite sites list of a person using DELETE call on "people/{personId}/favorite-sites/{siteId}" * Remove a specific site from favorite sites list of a person using DELETE call on "people/{personId}/favorite-sites/{siteId}"
*/ */
@@ -334,7 +341,7 @@ public class People extends ModelRequest<People>
*/ */
public RestWrapper deleteSiteFromFavorites(SiteModel site) public RestWrapper deleteSiteFromFavorites(SiteModel site)
{ {
RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/favorites/{favoriteId}", this.person.getUsername(), site.getGuid()); RestRequest request = RestRequest.simpleRequest(HttpMethod.DELETE, "people/{personId}/favorites/{favoriteId}", this.person.getUsername(), site.getGuid());
restWrapper.processEmptyModel(request); restWrapper.processEmptyModel(request);
return restWrapper; return restWrapper;
} }
@@ -379,7 +386,7 @@ public class People extends ModelRequest<People>
public RestNetworkModel getNetwork(UserModel tenant) public RestNetworkModel getNetwork(UserModel tenant)
{ {
Utility.checkObjectIsInitialized(tenant.getDomain(), "tenant.getDomain()"); Utility.checkObjectIsInitialized(tenant.getDomain(), "tenant.getDomain()");
String personId = tenant.getUsername().contains("-me-@")? "-me-" : tenant.getUsername(); String personId = tenant.getUsername().contains("-me-@") ? "-me-" : tenant.getUsername();
RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/networks/{networkId}?{parameters}", personId, tenant.getDomain(), restWrapper.getParameters()); RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, "people/{personId}/networks/{networkId}?{parameters}", personId, tenant.getDomain(), restWrapper.getParameters());
return restWrapper.processModel(RestNetworkModel.class, request); return restWrapper.processModel(RestNetworkModel.class, request);
} }
@@ -410,10 +417,9 @@ public class People extends ModelRequest<People>
RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, newPerson.toJson(), "people"); RestRequest request = RestRequest.requestWithBody(HttpMethod.POST, newPerson.toJson(), "people");
return restWrapper.processModel(RestPersonModel.class, request); return restWrapper.processModel(RestPersonModel.class, request);
} }
/** /**
* Get people avatar image using GET call on '/people/{personId}/avatar Please note that it retries to get the * Get people avatar image using GET call on '/people/{personId}/avatar Please note that it retries to get the renditions response several times because on the alfresco server the rendition can take a while to be created.
* renditions response several times because on the alfresco server the rendition can take a while to be created.
*/ */
public RestResponse downloadAvatarContent() public RestResponse downloadAvatarContent()
{ {
@@ -456,17 +462,8 @@ public class People extends ModelRequest<People>
return new WhereClause(this); return new WhereClause(this);
} }
/** /**
* Construct the Where clause of getFavorites * Construct the Where clause of getFavorites You can use the where parameter to restrict the list in the response to entries of a specific kind. The where parameter takes a value. The value is a single predicate that can include one or more EXISTS conditions. The EXISTS condition uses a single operand to limit the list to include entries that include that one property. The property values are:- target/file target/folder target/site Usage: where.. targetFileExist().or().targetSiteExist().filterAnd().getFavorites(...) At this point this method is working only with @link {@link RestFavoritesApi#getFavorites(UserModel) method.
* You can use the where parameter to restrict the list in the response to entries of a specific kind. The where parameter takes a value. The value is a
* single predicate that can include one or more EXISTS conditions. The EXISTS condition uses a single operand to limit the list to include entries that
* include that one property. The property values are:-
* target/file
* target/folder
* target/site
* Usage:
* where.. targetFileExist().or().targetSiteExist().filterAnd().getFavorites(...)
* At this point this method is working only with @link {@link RestFavoritesApi#getFavorites(UserModel) method.
* *
* @author paul.brodner * @author paul.brodner
*/ */

View File

@@ -1,5 +1,11 @@
package org.alfresco.rest.people.preferences; package org.alfresco.rest.people.preferences;
import java.nio.file.Paths;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel; import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestPreferenceModel; import org.alfresco.rest.model.RestPreferenceModel;
@@ -9,11 +15,6 @@ import org.alfresco.utility.model.*;
import org.alfresco.utility.report.Bug; import org.alfresco.utility.report.Bug;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail; import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.nio.file.Paths;
public class GetPeoplePreferenceFullTests extends RestTest public class GetPeoplePreferenceFullTests extends RestTest
{ {
@@ -29,53 +30,53 @@ public class GetPeoplePreferenceFullTests extends RestTest
dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites(); dataSite.usingUser(userModel).usingSite(siteModel).addSiteToFavorites();
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Check that properties parameter is applied") description = "Check that properties parameter is applied")
public void propertiesParameterIsAppliedWhenRetrievingPreference() throws Exception public void propertiesParameterIsAppliedWhenRetrievingPreference() throws Exception
{ {
restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id").withCoreAPI().usingUser(userModel) restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id").withCoreAPI().usingUser(userModel)
.getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()));
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()))
.and().field("value").isNull(); .and().field("value").isNull();
restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id,value").withCoreAPI().usingUser(userModel) restPreferenceModel = restClient.authenticateUser(userModel).withParams("properties=id,value").withCoreAPI().usingUser(userModel)
.getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()));
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()))
.and().field("value").is("true"); .and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Validate ID element in get site preference response") description = "Validate ID element in get site preference response")
public void validateIdElementInGetSitePreferenceResponse() throws Exception public void validateIdElementInGetSitePreferenceResponse() throws Exception
{ {
restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())); .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()));
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())) restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()))
.and().field("value").is("true"); .and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Validate ID element in get folder preference response") description = "Validate ID element in get folder preference response")
public void validateIdElementInGetFolderPreferenceResponse() throws Exception public void validateIdElementInGetFolderPreferenceResponse() throws Exception
{ {
FolderModel folderFavorite = new FolderModel("favoriteFolder"); FolderModel folderFavorite = new FolderModel("favoriteFolder");
folderFavorite = dataContent.usingSite(siteModel).createFolder(folderFavorite); folderFavorite = dataContent.usingSite(siteModel).createFolder(folderFavorite);
dataContent.getContentActions().setFolderAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), folderFavorite.getName()); dataContent.getContentActions().setFolderAsFavorite(userModel.getUsername(), userModel.getPassword(), siteModel.getId(), folderFavorite.getName());
restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString());
restPreferenceModel.assertThat().field("id").is(PreferenceName.FOLDERS_FAVORITES_PREFIX) restPreferenceModel.assertThat().field("id").is(PreferenceName.FOLDERS_FAVORITES_PREFIX)
.and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", folderFavorite.getNodeRef()))); .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", folderFavorite.getNodeRef())));
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Validate ID element in get file preference response") description = "Validate ID element in get file preference response")
public void validateIdElementInGetFilePreferenceResponse() throws Exception public void validateIdElementInGetFilePreferenceResponse() throws Exception
{ {
FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN);
@@ -85,86 +86,86 @@ public class GetPeoplePreferenceFullTests extends RestTest
restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(userModel).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString());
restPreferenceModel.assertThat().field("id").is(PreferenceName.DOCUMENTS_FAVORITES_PREFIX) restPreferenceModel.assertThat().field("id").is(PreferenceName.DOCUMENTS_FAVORITES_PREFIX)
.and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", fileFavorite.getNodeRefWithoutVersion()))); .and().field("value").is(Utility.removeLastSlash(Utility.buildPath("workspace://SpacesStore", fileFavorite.getNodeRefWithoutVersion())));
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Get preference of an user that has no preferences") description = "Get preference of an user that has no preferences")
public void getPreferenceForUserWithoutPreferences() throws Exception public void getPreferenceForUserWithoutPreferences() throws Exception
{ {
UserModel newUser = dataUser.createRandomTestUser(); UserModel newUser = dataUser.createRandomTestUser();
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()));
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()));
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.SITES_FAVORITES_PREFIX.toString())); PreferenceName.SITES_FAVORITES_PREFIX.toString()));
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Change one preference for an user then perform get call") description = "Change one preference for an user then perform get call")
@Bug(id = "REPO-1922") @Bug(id = "REPO-1922")
public void changePreferenceThenPerformGetPreferenceCall() throws Exception public void changePreferenceThenPerformGetPreferenceCall() throws Exception
{ {
UserModel newUser = dataUser.createRandomTestUser(); UserModel newUser = dataUser.createRandomTestUser();
SiteModel site = dataSite.usingUser(newUser).createPublicRandomSite(); SiteModel site = dataSite.usingUser(newUser).createPublicRandomSite();
dataSite.usingUser(newUser).usingSite(site).addSiteToFavorites(); dataSite.usingUser(newUser).usingSite(site).addSiteToFavorites();
FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN); FileModel fileFavorite = new FileModel("favoriteFile", FileType.TEXT_PLAIN);
fileFavorite = dataContent.usingSite(site).createContent(fileFavorite); fileFavorite = dataContent.usingSite(site).createContent(fileFavorite);
dataContent.getContentActions().setFileAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), String.format("%s.%s", fileFavorite.getName(), fileFavorite.getFileType().extension)); dataContent.getContentActions().setFileAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), String.format("%s.%s", fileFavorite.getName(), fileFavorite.getFileType().extension));
FolderModel folderFavorite = new FolderModel("favoriteFolder"); FolderModel folderFavorite = new FolderModel("favoriteFolder");
folderFavorite = dataContent.usingSite(site).createFolder(folderFavorite); folderFavorite = dataContent.usingSite(site).createFolder(folderFavorite);
dataContent.getContentActions().setFolderAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); dataContent.getContentActions().setFolderAsFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName());
dataSite.usingUser(newUser).usingSite(site).removeSiteFromFavorites(); dataSite.usingUser(newUser).usingSite(site).removeSiteFromFavorites();
dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName()); dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), folderFavorite.getName());
dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), Paths.get(fileFavorite.getCmisLocation()).getFileName().toString()); dataContent.getContentActions().removeFavorite(newUser.getUsername(), newUser.getPassword(), site.getId(), Paths.get(fileFavorite.getCmisLocation()).getFileName().toString());
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()));
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.SITES_FAVORITES_PREFIX.toString())); PreferenceName.SITES_FAVORITES_PREFIX.toString()));
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString())); PreferenceName.DOCUMENTS_FAVORITES_PREFIX.toString()));
restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()); .getPersonPreferenceInformation(PreferenceName.FOLDERS_FAVORITES_PREFIX.toString());
restClient.assertLastError().containsSummary( restClient.assertLastError().containsSummary(
String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(), String.format("The relationship resource was not found for the" + " entity with id: %s and a relationship id of %s", newUser.getUsername(),
PreferenceName.FOLDERS_FAVORITES_PREFIX.toString())); PreferenceName.FOLDERS_FAVORITES_PREFIX.toString()));
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Verify admin is able to get preference of another user") description = "Verify admin is able to get preference of another user")
public void adminIsAbleToGetOtherUserPreference() throws Exception public void adminIsAbleToGetOtherUserPreference() throws Exception
{ {
restPreferenceModel = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel) restPreferenceModel = restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(userModel)
@@ -172,18 +173,62 @@ public class GetPeoplePreferenceFullTests extends RestTest
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.REGRESSION, @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Verify regular user is not able to get preference of admin user") description = "Verify regular user is not able to get preference of admin user")
public void regularUserIsNotAbleToGetAdminPreference() throws Exception public void regularUserIsNotAbleToGetAdminPreference() throws Exception
{ {
SiteModel newSite = dataSite.usingUser(dataUser.getAdminUser()).createPublicRandomSite(); SiteModel newSite = dataSite.usingUser(dataUser.getAdminUser()).createPublicRandomSite();
dataSite.usingUser(dataUser.getAdminUser()).usingSite(newSite).addSiteToFavorites(); dataSite.usingUser(dataUser.getAdminUser()).usingSite(newSite).addSiteToFavorites();
restClient.authenticateUser(userModel).withCoreAPI().usingUser(dataUser.getAdminUser()) restClient.authenticateUser(userModel).withCoreAPI().usingUser(dataUser.getAdminUser())
.getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + newSite.getId()); .getPersonPreferenceInformation(PreferenceName.SITES_FAVORITES_PREFIX + newSite.getId());
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN);
restClient.assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED); restClient.assertLastError().containsSummary(RestErrorModel.PERMISSION_WAS_DENIED);
} }
}
@Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION})
@TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Verify regular user is able to change own preferences")
public void regularUserIsAbleToChangeOwnPreference() throws Exception
{
var newUser = dataUser.createRandomTestUser();
var newSite = dataSite.usingUser(newUser).createPublicRandomSite();
var preferenceId = String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), newSite.getId());
var updatedPreferenceModel = new RestPreferenceModel();
updatedPreferenceModel.setId(preferenceId);
updatedPreferenceModel.setValue("");
dataSite.usingUser(newUser).usingSite(newSite).addSiteToFavorites();
restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(preferenceId);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser().updatePersonPreferenceInformation(preferenceId, updatedPreferenceModel);
restClient.assertStatusCodeIs(HttpStatus.OK);
var personPreferences = restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser().getPersonPreferences();
personPreferences.assertThat().entriesListDoesNotContain("id", preferenceId);
}
@Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.REGRESSION})
@TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.REGRESSION,
description = "Verify admin is not able to change regular user preferences")
public void adminIsNotAbleToChangeRegularUserPreference() throws Exception
{
var newUser = dataUser.createRandomTestUser();
var newSite = dataSite.usingUser(newUser).createPublicRandomSite();
var preferenceId = String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), newSite.getId());
var updatedPreferenceModel = new RestPreferenceModel();
updatedPreferenceModel.setId(preferenceId);
updatedPreferenceModel.setValue("");
dataSite.usingUser(newUser).usingSite(newSite).addSiteToFavorites();
restClient.authenticateUser(newUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(preferenceId);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingUser(newUser).updatePersonPreferenceInformation(preferenceId, updatedPreferenceModel);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
}
}

View File

@@ -1,7 +1,10 @@
package org.alfresco.rest.people.preferences; package org.alfresco.rest.people.preferences;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestErrorModel;
import org.alfresco.rest.model.RestPreferenceModel; import org.alfresco.rest.model.RestPreferenceModel;
import org.alfresco.utility.constants.PreferenceName; import org.alfresco.utility.constants.PreferenceName;
import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.constants.UserRole;
@@ -10,9 +13,6 @@ import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel; import org.alfresco.utility.model.UserModel;
import org.alfresco.utility.testrail.ExecutionType; import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail; import org.alfresco.utility.testrail.annotation.TestRail;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/** /**
* Tests for Get a Peference (/people/{personId}/preferences/{preferenceName}) RestAPI call * Tests for Get a Peference (/people/{personId}/preferences/{preferenceName}) RestAPI call
@@ -33,8 +33,8 @@ public class GetPeoplePreferenceSanityTests extends RestTest
siteModel = dataSite.usingUser(userModel).createPublicRandomSite(); siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user gets a specific preference with Rest API and response is successful (200)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify manager user gets a specific preference with Rest API and response is successful (200)")
public void managerUserGetsAPreferenceWithSuccess() throws Exception public void managerUserGetsAPreferenceWithSuccess() throws Exception
{ {
UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); UserModel managerUser = dataUser.usingAdmin().createRandomTestUser();
@@ -47,8 +47,8 @@ public class GetPeoplePreferenceSanityTests extends RestTest
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets a specific preference with Rest API and response is successful (200)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets a specific preference with Rest API and response is successful (200)")
public void collaboratorUserGetsAPreferenceWithSuccess() throws Exception public void collaboratorUserGetsAPreferenceWithSuccess() throws Exception
{ {
UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser(); UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser();
@@ -61,8 +61,24 @@ public class GetPeoplePreferenceSanityTests extends RestTest
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify contributor user gets a specific preference with Rest API and response is successful (200)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify collaborator user gets a specific preference with Rest API and response is successful (200)")
public void collaboratorUserUpdatesAPreferenceWithSuccess() throws Exception
{
UserModel collaboratorUser = dataUser.usingAdmin().createRandomTestUser();
var updatedRestPreferenceModel = new RestPreferenceModel();
updatedRestPreferenceModel.setId("user.preference");
updatedRestPreferenceModel.setValue("user.value");
restPreferenceModel = restClient.authenticateUser(collaboratorUser).withCoreAPI().usingAuthUser()
.updatePersonPreferenceInformation(updatedRestPreferenceModel.getId(), updatedRestPreferenceModel);
restClient.assertStatusCodeIs(HttpStatus.OK);
restPreferenceModel.assertThat().field("id").is("user.preference").and().field("value").is("user.value");
}
@Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify contributor user gets a specific preference with Rest API and response is successful (200)")
public void contributorUserGetsAPreferenceWithSuccess() throws Exception public void contributorUserGetsAPreferenceWithSuccess() throws Exception
{ {
UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser(); UserModel contributorUser = dataUser.usingAdmin().createRandomTestUser();
@@ -75,8 +91,8 @@ public class GetPeoplePreferenceSanityTests extends RestTest
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API,TestGroup.PEOPLE, TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify consumer user gets a specific preference with Rest API and response is successful (200)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify consumer user gets a specific preference with Rest API and response is successful (200)")
public void consumerUserGetsAPreferenceWithSuccess() throws Exception public void consumerUserGetsAPreferenceWithSuccess() throws Exception
{ {
UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser(); UserModel consumerUser = dataUser.usingAdmin().createRandomTestUser();
@@ -84,13 +100,13 @@ public class GetPeoplePreferenceSanityTests extends RestTest
dataSite.usingUser(consumerUser).usingSite(siteModel).addSiteToFavorites(); dataSite.usingUser(consumerUser).usingSite(siteModel).addSiteToFavorites();
restPreferenceModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser() restPreferenceModel = restClient.authenticateUser(consumerUser).withCoreAPI().usingAuthUser()
.getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(),siteModel.getId())); .getPersonPreferenceInformation(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId()));
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(),siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify admin user gets a specific preference with Rest API and response is successful (200)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify admin user gets a specific preference with Rest API and response is successful (200)")
public void adminUserGetsAPreferenceWithSuccess() throws Exception public void adminUserGetsAPreferenceWithSuccess() throws Exception
{ {
UserModel adminUser = dataUser.getAdminUser(); UserModel adminUser = dataUser.getAdminUser();
@@ -102,9 +118,9 @@ public class GetPeoplePreferenceSanityTests extends RestTest
restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true"); restPreferenceModel.assertThat().field("id").is(String.format(PreferenceName.SITES_FAVORITES_PREFIX.toString(), siteModel.getId())).and().field("value").is("true");
} }
@Test(groups = { TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY }) @Test(groups = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES, TestGroup.SANITY})
@TestRail(section = { TestGroup.REST_API, TestGroup.PEOPLE,TestGroup.PREFERENCES }, executionType = ExecutionType.SANITY, description = "Verify manager user is NOT Authorized to get a specific preference with Rest API when authentication fails (401)") @TestRail(section = {TestGroup.REST_API, TestGroup.PEOPLE, TestGroup.PREFERENCES}, executionType = ExecutionType.SANITY, description = "Verify manager user is NOT Authorized to get a specific preference with Rest API when authentication fails (401)")
// @Bug(id = "MNT-16904", description = "fails only on environment with tenants") // @Bug(id = "MNT-16904", description = "fails only on environment with tenants")
public void managerUserNotAuthorizedFailsToGetsAPreference() throws Exception public void managerUserNotAuthorizedFailsToGetsAPreference() throws Exception
{ {
UserModel managerUser = dataUser.usingAdmin().createRandomTestUser(); UserModel managerUser = dataUser.usingAdmin().createRandomTestUser();

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -23,14 +23,17 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api; package org.alfresco.rest.api;
import org.alfresco.rest.api.model.Preference; import org.alfresco.rest.api.model.Preference;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
public interface Preferences public interface Preferences
{ {
public Preference getPreference(String personId, String preferenceName); Preference getPreference(String personId, String preferenceName);
public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging);
} CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging);
Preference updatePreference(String personId, Preference preference);
}

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -23,69 +23,92 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.impl; package org.alfresco.rest.api.impl;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.HashMap;
import java.util.List;
import org.alfresco.query.PagingResults; import java.util.Map;
import org.alfresco.rest.api.People;
import org.alfresco.rest.api.Preferences; import org.alfresco.query.PagingResults;
import org.alfresco.rest.api.model.Preference; import org.alfresco.rest.api.People;
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.api.Preferences;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.api.model.Preference;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
import org.alfresco.service.cmr.preference.PreferenceService; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.util.Pair; import org.alfresco.rest.framework.resource.parameters.Paging;
import org.alfresco.service.cmr.preference.PreferenceService;
/** import org.alfresco.util.Pair;
* Centralises access to preference services and maps between representations.
* /**
* @author steveglover * Centralises access to preference services and maps between representations.
* @since publicapi1.0 *
*/ * @author steveglover
public class PreferencesImpl implements Preferences * @since publicapi1.0
{ */
private People people; public class PreferencesImpl implements Preferences
private PreferenceService preferenceService; {
private People people;
public void setPeople(People people) private PreferenceService preferenceService;
{
this.people = people; public void setPeople(People people)
} {
this.people = people;
public void setPreferenceService(PreferenceService preferenceService) }
{
this.preferenceService = preferenceService; public void setPreferenceService(PreferenceService preferenceService)
} {
this.preferenceService = preferenceService;
public Preference getPreference(String personId, String preferenceName) }
{
personId = people.validatePerson(personId); @Override
Serializable preferenceValue = preferenceService.getPreference(personId, preferenceName); public Preference getPreference(String personId, String preferenceName)
if(preferenceValue != null) {
{ personId = people.validatePerson(personId);
return new Preference(preferenceName, preferenceValue); Serializable preferenceValue = preferenceService.getPreference(personId, preferenceName);
} if (preferenceValue != null)
else {
{ return new Preference(preferenceName, preferenceValue);
throw new RelationshipResourceNotFoundException(personId, preferenceName); }
} else
} {
throw new RelationshipResourceNotFoundException(personId, preferenceName);
public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging) }
{ }
personId = people.validatePerson(personId);
@Override
PagingResults<Pair<String, Serializable>> preferences = preferenceService.getPagedPreferences(personId, null, Util.getPagingRequest(paging)); public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging)
List<Preference> ret = new ArrayList<Preference>(preferences.getPage().size()); {
for(Pair<String, Serializable> prefEntity : preferences.getPage()) personId = people.validatePerson(personId);
{
Preference pref = new Preference(prefEntity.getFirst(), prefEntity.getSecond()); PagingResults<Pair<String, Serializable>> preferences = preferenceService.getPagedPreferences(personId, null, Util.getPagingRequest(paging));
ret.add(pref); List<Preference> ret = new ArrayList<>(preferences.getPage().size());
} for (Pair<String, Serializable> prefEntity : preferences.getPage())
{
return CollectionWithPagingInfo.asPaged(paging, ret, preferences.hasMoreItems(), preferences.getTotalResultCount().getFirst()); Preference pref = new Preference(prefEntity.getFirst(), prefEntity.getSecond());
} ret.add(pref);
} }
return CollectionWithPagingInfo.asPaged(paging, ret, preferences.hasMoreItems(), preferences.getTotalResultCount().getFirst());
}
@Override
public Preference updatePreference(String personId, Preference preference)
{
personId = people.validatePerson(personId, true);
final Map<String, Serializable> preferencesToSet;
if (preference.getValue() == null || "".equals(preference.getValue()))
{
preferencesToSet = new HashMap<>(1);
preferencesToSet.put(preference.getName(), null);
}
else
{
preferencesToSet = Map.of(preference.getName(), preference.getValue());
}
preferenceService.setPreferences(personId, preferencesToSet);
return new Preference(preference.getName(), preferenceService.getPreference(personId, preference.getName()));
}
}

View File

@@ -1,93 +1,105 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.people; package org.alfresco.rest.api.people;
import org.alfresco.rest.api.Preferences; import org.apache.commons.logging.Log;
import org.alfresco.rest.api.model.Preference; import org.apache.commons.logging.LogFactory;
import org.alfresco.rest.framework.WebApiDescription; import org.springframework.beans.factory.InitializingBean;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.api.Preferences;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.api.model.Preference;
import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.util.ParameterCheck; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.apache.commons.logging.Log; import org.alfresco.rest.framework.resource.RelationshipResource;
import org.apache.commons.logging.LogFactory; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.springframework.beans.factory.InitializingBean; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
@RelationshipResource(name = "preferences", entityResource = PeopleEntityResource.class, title = "Person Preferences") import org.alfresco.util.ParameterCheck;
public class PersonPreferencesRelation implements RelationshipResourceAction.Read<Preference>, RelationshipResourceAction.ReadById<Preference>, InitializingBean
{ @RelationshipResource(name = "preferences", entityResource = PeopleEntityResource.class, title = "Person Preferences")
private static final Log logger = LogFactory.getLog(PersonPreferencesRelation.class); public class PersonPreferencesRelation implements RelationshipResourceAction.Read<Preference>, RelationshipResourceAction.ReadById<Preference>, RelationshipResourceAction.Update<Preference>, InitializingBean
{
private Preferences preferences; private static final Log logger = LogFactory.getLog(PersonPreferencesRelation.class);
public void setPreferences(Preferences preferences) private Preferences preferences;
{
this.preferences = preferences; public void setPreferences(Preferences preferences)
} {
this.preferences = preferences;
@Override }
public void afterPropertiesSet()
{ @Override
ParameterCheck.mandatory("preferences", this.preferences); public void afterPropertiesSet()
} {
ParameterCheck.mandatory("preferences", this.preferences);
/** }
* Returns a paged list of preferences for the user personId.
* /**
* If personId does not exist, NotFoundException (status 404). * Returns a paged list of preferences for the user personId.
* *
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.Read#readAll(java.lang.String, org.alfresco.rest.framework.resource.parameters.Parameters) * If personId does not exist, NotFoundException (status 404).
*/ *
@Override * @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.Read#readAll(java.lang.String, org.alfresco.rest.framework.resource.parameters.Parameters)
@WebApiDescription(title = "A paged list of the persons preferences.") */
public CollectionWithPagingInfo<Preference> readAll(String personId, Parameters parameters) @Override
{ @WebApiDescription(title = "A paged list of the persons preferences.")
return preferences.getPreferences(personId, parameters.getPaging()); public CollectionWithPagingInfo<Preference> readAll(String personId, Parameters parameters)
} {
return preferences.getPreferences(personId, parameters.getPaging());
/** }
* Returns information regarding the preference 'preferenceName' for user personId.
* /**
* If personId does not exist, NotFoundException (status 404). * Returns information regarding the preference 'preferenceName' for user personId.
* *
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById#readById(String, String, org.alfresco.rest.framework.resource.parameters.Parameters) * If personId does not exist, NotFoundException (status 404).
*/ *
@Override * @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById#readById(String, String, org.alfresco.rest.framework.resource.parameters.Parameters)
@WebApiDescription(title = "Preference value for preference 'preferenceName' for person 'personId'.") */
public Preference readById(String personId, String preferenceName, Parameters parameters) @Override
{ @WebApiDescription(title = "Preference value for preference 'preferenceName' for person 'personId'.")
// fix for REPO-855 public Preference readById(String personId, String preferenceName, Parameters parameters)
String url = parameters.getRequest().getURL(); {
if(url.matches(".*workspace://SpacesStore/.*")){ // fix for REPO-855
preferenceName += url.substring(url.indexOf("//SpacesStore/")); String url = parameters.getRequest().getURL();
} if (url.matches(".*workspace://SpacesStore/.*"))
// {
preferenceName += url.substring(url.indexOf("//SpacesStore/"));
return preferences.getPreference(personId, preferenceName); }
} //
} return preferences.getPreference(personId, preferenceName);
}
@Override
public Preference update(String personId, Preference preference, Parameters parameters)
{
if (preference.getName() == null || preference.getName().isBlank())
{
throw new InvalidArgumentException();
}
return preferences.updatePreference(personId, preference);
}
}

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -30,6 +30,15 @@ import java.io.InputStream;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.rest.framework.core.ResourceLocator; import org.alfresco.rest.framework.core.ResourceLocator;
import org.alfresco.rest.framework.core.ResourceMetadata; import org.alfresco.rest.framework.core.ResourceMetadata;
@@ -47,14 +56,7 @@ import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams; import org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams;
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor; import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
import org.alfresco.rest.framework.tools.RequestReader; import org.alfresco.rest.framework.tools.RequestReader;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
/** /**
* Handles the HTTP PUT for a Resource, equivalent to CRUD Update * Handles the HTTP PUT for a Resource, equivalent to CRUD Update
* *
@@ -64,15 +66,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
RecognizedParamsExtractor, RequestReader RecognizedParamsExtractor, RequestReader
{ {
private static Log logger = LogFactory.getLog(ResourceWebScriptPut.class); private static final Log logger = LogFactory.getLog(ResourceWebScriptPut.class);
public ResourceWebScriptPut() public ResourceWebScriptPut()
{ {
super(); super();
setHttpMethod(HttpMethod.PUT); setHttpMethod(HttpMethod.PUT);
setParamsExtractor(this); setParamsExtractor(this);
} }
@Override @Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req)
{ {
@@ -86,81 +88,87 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
switch (resourceMeta.getType()) switch (resourceMeta.getType())
{ {
case ENTITY: case ENTITY:
if (StringUtils.isBlank(entityId)) if (StringUtils.isBlank(entityId))
{ {
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL"); throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
} else }
{ else
{
Object putEnt = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation)); Object putEnt = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
return Params.valueOf(entityId,params,putEnt, req); return Params.valueOf(entityId, params, putEnt, req);
} }
case RELATIONSHIP: case RELATIONSHIP:
if (StringUtils.isBlank(relationshipId)) if (StringUtils.isBlank(relationshipId))
{
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
}
Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
if (StringUtils.isNotBlank(relationship2Id))
{
ResourceWebScriptHelper.setUniqueId(putRel, relationship2Id);
return Params.valueOf(false, entityId, relationshipId, relationship2Id,
putRel, null, null, params, null, req);
}
else
{
ResourceWebScriptHelper.setUniqueId(putRel, relationshipId);
return Params.valueOf(entityId, relationshipId, params, putRel, req);
}
case PROPERTY:
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName))
{
if (StringUtils.isNotBlank(propertyName))
{ {
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL"); return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req);
}
Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
if (StringUtils.isNotBlank(relationship2Id))
{
ResourceWebScriptHelper.setUniqueId(putRel, relationship2Id);
return Params.valueOf(false, entityId, relationshipId, relationship2Id,
putRel, null, null, params, null, req);
} }
else else
{ {
ResourceWebScriptHelper.setUniqueId(putRel,relationshipId); return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req);
return Params.valueOf(entityId, params, putRel, req);
} }
case PROPERTY:
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName)) }
{ // Fall through to unsupported.
if (StringUtils.isNotBlank(propertyName)) default:
{ throw new UnsupportedResourceOperationException("PUT not supported for this request.");
return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req);
}
else
{
return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req);
}
}
//Fall through to unsupported.
default:
throw new UnsupportedResourceOperationException("PUT not supported for this request.");
} }
} }
/** /**
* Returns the basic content info from the request. * Returns the basic content info from the request.
* @param req WebScriptRequest *
* @param req
* WebScriptRequest
* @return BasicContentInfo * @return BasicContentInfo
*/ */
private BasicContentInfo getContentInfo(WebScriptRequest req) { private BasicContentInfo getContentInfo(WebScriptRequest req)
{
String encoding = "UTF-8";
String contentType = MimetypeMap.MIMETYPE_BINARY; String encoding = "UTF-8";
String contentType = MimetypeMap.MIMETYPE_BINARY;
if (StringUtils.isNotEmpty(req.getContentType()))
{ if (StringUtils.isNotEmpty(req.getContentType()))
MediaType media = MediaType.parseMediaType(req.getContentType()); {
contentType = media.getType()+'/'+media.getSubtype(); MediaType media = MediaType.parseMediaType(req.getContentType());
if (media.getCharset() != null) contentType = media.getType() + '/' + media.getSubtype();
{ if (media.getCharset() != null)
encoding = media.getCharset().toString(); {
} encoding = media.getCharset().toString();
} }
}
return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault()); return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault());
} }
/** /**
* Returns the input stream for the request * Returns the input stream for the request
* @param req WebScriptRequest *
* @param req
* WebScriptRequest
* @return InputStream * @return InputStream
*/ */
private InputStream getStream(WebScriptRequest req) private InputStream getStream(WebScriptRequest req)
@@ -186,11 +194,14 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
return null; return null;
} }
/** /**
* Executes the action on the resource * Executes the action on the resource
* @param resource ResourceWithMetadata *
* @param params parameters to use * @param resource
* ResourceWithMetadata
* @param params
* parameters to use
* @return anObject the result of the execute * @return anObject the result of the execute
*/ */
@Override @Override
@@ -198,87 +209,87 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
{ {
switch (resource.getMetaData().getType()) switch (resource.getMetaData().getType())
{ {
case ENTITY: case ENTITY:
if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass())) if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class))
{ {
if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) resource.getResource();
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params);
return result;
} }
else EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) resource.getResource();
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params);
return result;
}
else
{
if (resource.getMetaData().isDeleted(EntityResourceAction.UpdateWithResponse.class))
{ {
if (resource.getMetaData().isDeleted(EntityResourceAction.UpdateWithResponse.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.UpdateWithResponse<Object> updateEnt = (EntityResourceAction.UpdateWithResponse<Object>) resource.getResource();
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return result;
} }
case RELATIONSHIP: EntityResourceAction.UpdateWithResponse<Object> updateEnt = (EntityResourceAction.UpdateWithResponse<Object>) resource.getResource();
if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return result;
}
case RELATIONSHIP:
if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class))
{ {
if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.UpdateWithResponse<Object> relationUpdater = (RelationshipResourceAction.UpdateWithResponse<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return relResult;
} }
else RelationshipResourceAction.UpdateWithResponse<Object> relationUpdater = (RelationshipResourceAction.UpdateWithResponse<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return relResult;
}
else
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class))
{ {
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
return relResult;
} }
case PROPERTY: RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass())) Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
return relResult;
}
case PROPERTY:
if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.Update.class))
{ {
if (resource.getMetaData().isDeleted(BinaryResourceAction.Update.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
} }
if (BinaryResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
}
if (BinaryResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.UpdateWithResponse.class))
{ {
if (resource.getMetaData().isDeleted(BinaryResourceAction.UpdateWithResponse.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
BinaryResourceAction.UpdateWithResponse<Object> binUpdater = (BinaryResourceAction.UpdateWithResponse<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params, withResponse);
} }
if (RelationshipResourceBinaryAction.Update.class.isAssignableFrom(resource.getResource().getClass())) BinaryResourceAction.UpdateWithResponse<Object> binUpdater = (BinaryResourceAction.UpdateWithResponse<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params, withResponse);
}
if (RelationshipResourceBinaryAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Update.class))
{ {
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Update.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceBinaryAction.Update<Object> binUpdater = (RelationshipResourceBinaryAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params);
} }
if (RelationshipResourceBinaryAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) RelationshipResourceBinaryAction.Update<Object> binUpdater = (RelationshipResourceBinaryAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params);
}
if (RelationshipResourceBinaryAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.UpdateWithResponse.class))
{ {
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.UpdateWithResponse.class)) throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceBinaryAction.UpdateWithResponse<Object> binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse);
} }
default: RelationshipResourceBinaryAction.UpdateWithResponse<Object> binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse<Object>) resource.getResource();
throw new UnsupportedResourceOperationException("PUT not supported for Actions"); return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse);
}
default:
throw new UnsupportedResourceOperationException("PUT not supported for Actions");
} }
} }

View File

@@ -1,416 +1,411 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2024 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.*; import java.util.*;
import org.alfresco.repo.tenant.TenantUtil; import org.apache.commons.httpclient.HttpStatus;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; import org.junit.Test;
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.RepoService.TestPerson; import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse; import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging; import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.client.PublicApiClient.People; import org.alfresco.rest.api.tests.RepoService.TestPerson;
import org.alfresco.rest.api.tests.client.PublicApiException; import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
import org.alfresco.rest.api.tests.client.data.Preference; import org.alfresco.rest.api.tests.client.PublicApiClient.People;
import org.alfresco.util.GUID; import org.alfresco.rest.api.tests.client.PublicApiException;
import org.apache.commons.httpclient.HttpStatus; import org.alfresco.rest.api.tests.client.RequestContext;
import org.junit.Test; import org.alfresco.rest.api.tests.client.data.Preference;
import org.alfresco.util.GUID;
public class TestUserPreferences extends EnterpriseTestApi
{ public class TestUserPreferences extends EnterpriseTestApi
@Test {
public void testUserPreferences() throws Exception @Test
{ public void testUserPreferences() throws Exception
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt(); {
assertTrue(networksIt.hasNext()); Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
final TestNetwork network1 = networksIt.next(); assertTrue(networksIt.hasNext());
assertTrue(networksIt.hasNext()); final TestNetwork network1 = networksIt.next();
final TestNetwork network2 = networksIt.next(); assertTrue(networksIt.hasNext());
final TestNetwork network2 = networksIt.next();
final List<TestPerson> people = new ArrayList<TestPerson>(3);
final List<TestPerson> people = new ArrayList<TestPerson>(3);
// create users and some preferences
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() // create users and some preferences
{ TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override @Override
public Void doWork() throws Exception public Void doWork() throws Exception
{ {
TestPerson person = network1.createUser(); TestPerson person = network1.createUser();
people.add(person); people.add(person);
person = network1.createUser(); person = network1.createUser();
people.add(person); people.add(person);
return null; return null;
} }
}, network1.getId()); }, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
{ @Override
@Override public Void doWork() throws Exception
public Void doWork() throws Exception {
{ TestPerson person = network2.createUser();
TestPerson person = network2.createUser(); people.add(person);
people.add(person); return null;
return null; }
} }, network2.getId());
}, network2.getId());
final TestPerson person1 = people.get(0);
final TestPerson person1 = people.get(0); final TestPerson person2 = people.get(1);
final TestPerson person2 = people.get(1); final TestPerson person3 = people.get(2);
final TestPerson person3 = people.get(2);
final List<Preference> expectedPreferences = new ArrayList<Preference>();
final List<Preference> expectedPreferences = new ArrayList<Preference>(); expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true))); expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true))); expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true))); expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true))); // new preference name for issue REPO-855
// new preference name for issue REPO-855 expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() @Override
{ public Void doWork() throws Exception
@Override {
public Void doWork() throws Exception for (Preference pref : expectedPreferences)
{ {
for(Preference pref : expectedPreferences) // TODO add preferences thru api
{ repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
// TODO add preferences thru api }
repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
} return null;
}
return null; }, person1.getId(), network1.getId());
}
}, person1.getId(), network1.getId()); Collections.sort(expectedPreferences);
Collections.sort(expectedPreferences); People peopleProxy = publicApiClient.people();
People peopleProxy = publicApiClient.people(); // GET preferences
// Test case: cloud-1492
// GET preferences
// Test case: cloud-1492 // unknown user
try
// unknown user {
try int skipCount = 0;
{ int maxItems = 2;
int skipCount = 0; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
peopleProxy.getPreferences(GUID.generate(), createParams(paging, null)); fail();
}
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} // test paging
{
// test paging int skipCount = 0;
{ int maxItems = 2;
int skipCount = 0; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null)); }
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
} {
int skipCount = 2;
{ int maxItems = 10;
int skipCount = 2; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
int maxItems = 10; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null)); }
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
} // "-me-" user
{
// "-me-" user int skipCount = 0;
{ int maxItems = 2;
int skipCount = 0; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null)); }
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
} // invalid user - 404
try
// invalid user - 404 {
try int skipCount = 2;
{ int maxItems = 10;
int skipCount = 2; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
int maxItems = 10; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getPreferences("invalid.user", createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); fail("");
peopleProxy.getPreferences("invalid.user", createParams(paging, null)); }
fail(""); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} // user from another account - 401
try
// user from another account - 401 {
try int skipCount = 0;
{ int maxItems = 2;
int skipCount = 0; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId())); // ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); // checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
// ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null)); peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
// checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp); fail();
peopleProxy.getPreferences(person1.getId(), createParams(paging, null)); }
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
{ }
assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
} // another user from the same account - 403
try
// another user from the same account - 403 {
try int skipCount = 0;
{ int maxItems = 2;
int skipCount = 0; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId())); peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size()); fail();
peopleProxy.getPreferences(person1.getId(), createParams(paging, null)); }
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
} // get a single preference
// Test Case: cloud-1493
// get a single preference
// Test Case: cloud-1493 {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ Preference pref = expectedPreferences.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
Preference pref = expectedPreferences.get(0); pref.expected(ret);
Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId()); }
pref.expected(ret);
} // unknown person id
try
// unknown person id {
try Preference pref = expectedPreferences.get(0);
{ publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
Preference pref = expectedPreferences.get(0); peopleProxy.getPreference(GUID.generate(), pref.getId());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId())); fail();
peopleProxy.getPreference(GUID.generate(), pref.getId()); }
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} // unknown preference id
try
// unknown preference id {
try publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ peopleProxy.getPreference(person1.getId(), GUID.generate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); fail();
peopleProxy.getPreference(person1.getId(), GUID.generate()); }
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} // Invalid methods
// Test case: cloud-1968
// Invalid methods try
// Test case: cloud-1968 {
try Preference pref = expectedPreferences.get(0);
{
Preference pref = expectedPreferences.get(0); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); fail();
peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference"); }
fail(); catch (PublicApiException e)
} {
catch(PublicApiException e) assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
{ }
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
} {
Preference updatedPref = new Preference("preference.to.update", "updated.value");
try
{ publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
Preference pref = expectedPreferences.get(0); Preference response = peopleProxy.updatePreference(person1.getId(), updatedPref);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); assertEquals(updatedPref.getId(), response.getId());
peopleProxy.update("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to PUT a preference"); assertEquals(updatedPref.getValue(), response.getValue());
fail(); }
}
catch(PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); Preference pref = expectedPreferences.get(0);
}
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
try peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
{ fail();
Preference pref = expectedPreferences.get(0); }
catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference"); assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
fail(); }
}
catch(PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); Preference pref = expectedPreferences.get(0);
}
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
try peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
{ fail();
Preference pref = expectedPreferences.get(0); }
catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences"); assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
fail(); }
}
catch(PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); Preference pref = expectedPreferences.get(0);
}
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
try peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
{ fail();
Preference pref = expectedPreferences.get(0); }
catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences"); assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
fail(); }
}
catch(PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
} peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences");
fail();
try }
{ catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences"); assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
fail(); }
}
catch(PublicApiException e) {
{ // REPO-1061, REPO-890
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); try
} {
String skipCount = "a";
{ String maxItems = "hi";
// REPO-1061, REPO-890 HashMap<String, String> params = new HashMap<String, String>();
try params.put("skipCount", skipCount);
{ params.put("maxItems", maxItems);
String skipCount = "a"; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
String maxItems = "hi"; peopleProxy.getPreferences(person1.getId(), params);
HashMap<String, String> params = new HashMap<String, String>(); fail();
params.put("skipCount", skipCount); }
params.put("maxItems", maxItems); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
}
catch (PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); String skipCount = "a";
} String maxItems = "null";
HashMap<String, String> params = new HashMap<String, String>();
try params.put("skipCount", skipCount);
{ params.put("maxItems", maxItems);
String skipCount = "a"; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
String maxItems = "null"; peopleProxy.getPreferences(person1.getId(), params);
HashMap<String, String> params = new HashMap<String, String>(); fail();
params.put("skipCount", skipCount); }
params.put("maxItems", maxItems); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
}
catch (PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); String maxItems = "Red";
} HashMap<String, String> params = new HashMap<String, String>();
params.put("maxItems", maxItems);
try publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ peopleProxy.getPreferences(person1.getId(), params);
String maxItems = "Red"; fail();
HashMap<String, String> params = new HashMap<String, String>(); }
params.put("maxItems", maxItems); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
}
catch (PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); String skipCount = "yuck";
} HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
try publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ peopleProxy.getPreferences(person1.getId(), params);
String skipCount = "yuck"; fail();
HashMap<String, String> params = new HashMap<String, String>(); }
params.put("skipCount", skipCount); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
}
catch (PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); String skipCount = "-1";
} HashMap<String, String> params = new HashMap<String, String>();
params.put("skipCount", skipCount);
try publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ peopleProxy.getPreferences(person1.getId(), params);
String skipCount = "-1"; fail();
HashMap<String, String> params = new HashMap<String, String>(); }
params.put("skipCount", skipCount); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
}
catch (PublicApiException e) try
{ {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); String maxItems = "0";
} HashMap<String, String> params = new HashMap<String, String>();
params.put("maxItems", maxItems);
try publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
{ peopleProxy.getPreferences(person1.getId(), params);
String maxItems = "0"; fail();
HashMap<String, String> params = new HashMap<String, String>(); }
params.put("maxItems", maxItems); catch (PublicApiException e)
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); {
peopleProxy.getPreferences(person1.getId(), params); assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
fail(); }
} }
catch (PublicApiException e) }
{ }
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
}
}
}