RM-4159 Wrap the RestWrapper rather than extending it.

Previously we were hitting an issue where there were three beans all of the
type RestWrapper. This meant that Spring could not determine which bean
should be used when autowiring.  By wrapping the RestWrapper we ensure there
is only one bean of that type, and so Spring knows which bean to use (in the
TAS code).  After some debate I decided against renaming the RMRestWrapper
as RestWrapperWrapper.
This commit is contained in:
Tom Page
2017-01-25 11:07:11 +00:00
parent f62ad8768a
commit c7aaa7b2e9
2 changed files with 87 additions and 7 deletions

View File

@@ -26,10 +26,15 @@
*/
package org.alfresco.rest.core;
import org.alfresco.rest.exception.EmptyJsonResponseException;
import org.alfresco.rest.model.RestSiteModel;
import org.alfresco.rest.model.RestSiteModelsCollection;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
/**
@@ -38,11 +43,13 @@ import org.springframework.stereotype.Service;
* @author Tuna Aksoy
* @since 2.6
*/
@Primary
@Service
@Scope(value = "prototype")
public class RMRestWrapper extends RestWrapper
public class RMRestWrapper
{
/** The class that wraps the ReST APIs from core. */
@Autowired
private RestWrapper restWrapper;
@Autowired
private RMRestProperties rmRestProperties;
@@ -51,12 +58,25 @@ public class RMRestWrapper extends RestWrapper
return new RestIGCoreAPI(this, rmRestProperties);
}
@Override
public <T> T processModel(Class<T> classz, RestRequest restRequest)
/** Get the core class that wraps the ReST APIs. */
public RestWrapper getRestWrapper()
{
return restWrapper;
}
/** Authenticate specific user to Alfresco REST API */
public void authenticateUser(UserModel userModel)
{
restWrapper.authenticateUser(userModel);
}
/** Process responses for a collection of models as {@link RestSiteModelsCollection}. */
public FilePlanComponentsCollection processModels(Class<FilePlanComponentsCollection> classz,
RestRequest simpleRequest)
{
try
{
return super.processModel(classz, restRequest);
return restWrapper.processModels(classz, simpleRequest);
}
catch (Exception e)
{
@@ -65,4 +85,64 @@ public class RMRestWrapper extends RestWrapper
throw new RuntimeException(e);
}
}
/** Process responses for a single model as {@link RestSiteModel}. */
public <T> T processModel(Class<T> classz, RestRequest restRequest)
{
try
{
return restWrapper.processModel(classz, restRequest);
}
catch (Exception e)
{
// TODO Hopefully remove this check when TAS stops using checked exceptions.
// See https://gitlab.alfresco.com/tas/alfresco-tas-restapi-test/merge_requests/392
throw new RuntimeException(e);
}
}
/** Process a response that has no body - basically will need only the status code from it. */
public void processEmptyModel(RestRequest simpleRequest)
{
try
{
restWrapper.processEmptyModel(simpleRequest);
}
catch (EmptyJsonResponseException e)
{
// TODO Hopefully remove this check when TAS stops using checked exceptions.
// See https://gitlab.alfresco.com/tas/alfresco-tas-restapi-test/merge_requests/392
throw new RuntimeException(e);
}
}
/** Get the most recently returned status code. */
public String getStatusCode()
{
return restWrapper.getStatusCode();
}
/** Set the status code. This should only be needed when calling APIs without using the TAS framework. */
public void setStatusCode(String statusCode)
{
restWrapper.setStatusCode(statusCode);
}
/** Assert that a specific status code is returned. */
public void assertStatusCodeIs(HttpStatus statusCode)
{
restWrapper.assertStatusCodeIs(statusCode);
}
/** @return A parameters string that you could pass on the request ?param=value */
public String getParameters()
{
return restWrapper.getParameters();
}
/** Create a {@link UserModel} for a new test user. */
public UserModel getTestUser()
{
return restWrapper.getTestUser();
}
}

View File

@@ -52,7 +52,7 @@ public abstract class RMModelRequest extends ModelRequest
*/
public RMModelRequest(RMRestWrapper rmRestWrapper)
{
super(rmRestWrapper);
super(rmRestWrapper.getRestWrapper());
this.rmRestWrapper = rmRestWrapper;
}
}