use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.
the class RMSiteEntityResourceUnitTest method updateRMSiteCompliance.
@Test
public void updateRMSiteCompliance() throws Exception {
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setCompliance(RMSiteCompliance.STANDARD);
try {
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site compliance cannot be changed.");
} catch (InvalidArgumentException ex) {
assertEquals("Site update does not support field: compliance", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.
the class RMSiteEntityResourceUnitTest method updateRMSiteId.
@Test
public void updateRMSiteId() throws Exception {
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setId("newSiteID");
try {
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site id cannot be changed.");
} catch (InvalidArgumentException ex) {
assertEquals("Site update does not support field: id", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project records-management by Alfresco.
the class RMSiteEntityResourceUnitTest method updateRMSiteVisibility.
@Test
public void updateRMSiteVisibility() throws Exception {
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setVisibility(SiteVisibility.PRIVATE);
try {
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site visibility cannot be changed.");
} catch (InvalidArgumentException ex) {
assertEquals("Site update does not support field: visibility", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractor method getPaging.
/**
* Gets the default paging object
* @param skip
* @param maxItems
* @return
*/
default Paging getPaging(String skip, String maxItems) {
int skipped = Paging.DEFAULT_SKIP_COUNT;
int max = Paging.DEFAULT_MAX_ITEMS;
try {
if (skip != null) {
skipped = Integer.parseInt(skip);
}
if (maxItems != null) {
max = Integer.parseInt(maxItems);
}
if (skipped < 0) {
throw new InvalidArgumentException("Negative values not supported for skipCount.");
}
if (max < 1) {
throw new InvalidArgumentException("Only positive values supported for maxItems.");
}
} catch (NumberFormatException error) {
String errorMsg = "Invalid paging parameters skipCount: " + skip + ", maxItems:" + maxItems;
if (rpeLogger().isDebugEnabled()) {
rpeLogger().debug(errorMsg);
}
if (skip == null) {
errorMsg = "Invalid paging parameter maxItems:" + maxItems;
}
if (maxItems == null) {
errorMsg = "Invalid paging parameter skipCount:" + skip;
}
throw new InvalidArgumentException(errorMsg);
}
return Paging.valueOf(skipped, max);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class Api method valueOf.
/**
* Creates an valid instance of the Api object
* @param apiName a String in lowercase
* @param apiScope SCOPE
* @param apiVersion postive integer
* @return Api
*/
public static Api valueOf(String apiName, String apiScope, String apiVersion) throws InvalidArgumentException {
SCOPE scope = null;
int version = 1;
try {
if (!StringUtils.isAllLowerCase(apiName))
throw new InvalidArgumentException("Api name must be lowercase");
scope = SCOPE.valueOf(apiScope.toUpperCase());
version = Integer.parseInt(apiVersion);
if (version < 1)
throw new InvalidArgumentException("Version must be a positive integer.");
} catch (Exception error) {
// Just throw it on.
if (error instanceof InvalidArgumentException)
throw (InvalidArgumentException) error;
logger.debug("Invalid API definition: " + apiName + " " + apiScope + " " + apiVersion);
throw new InvalidArgumentException("Invalid API definition:" + error.getMessage());
}
Api anApi = new Api(apiName, scope, version);
return ALFRESCO_PUBLIC.equals(anApi) ? ALFRESCO_PUBLIC : anApi;
}
Aggregations