use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiGuiFragmentInterface method getGuiFragment.
public JAXBGuiFragment getGuiFragment(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
JAXBGuiFragment jaxbGuiFragment = null;
try {
GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
if (null == guiFragment) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with id '" + code + "' does not exist", Response.Status.CONFLICT);
}
jaxbGuiFragment = new JAXBGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating jaxb object of fragment - code '{}'", code, t);
throw t;
}
return jaxbGuiFragment;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiServiceInterface method getService.
public Object getService(Properties properties) throws ApiException {
Object response = null;
String key = (String) properties.get("key");
try {
ApiService service = this.getApiCatalogManager().getApiService(key);
if (null == service) {
throw new ApiException(IApiErrorCodes.API_SERVICE_INVALID, "Service '" + key + "' does not exist");
}
if (!service.isActive()) {
throw new ApiException(IApiErrorCodes.API_SERVICE_ACTIVE_FALSE, "Service '" + key + "' is not active");
}
this.checkServiceAuthorization(service, properties, true);
Properties serviceParameters = new Properties();
serviceParameters.putAll(service.getParameters());
Iterator<Object> paramIter = properties.keySet().iterator();
List<String> reservedParameters = Arrays.asList(SystemConstants.API_RESERVED_PARAMETERS);
while (paramIter.hasNext()) {
Object paramName = paramIter.next();
String paramNameString = paramName.toString();
if (reservedParameters.contains(paramNameString) || service.isFreeParameter(paramNameString)) {
serviceParameters.put(paramNameString, properties.get(paramName));
}
}
response = this.getResponseBuilder().createResponse(service.getMaster(), serviceParameters);
} catch (ApiException e) {
throw e;
} catch (Throwable t) {
_logger.error("Error invocating service - key '{}'", key, t);
throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class DefaultJAXBAttributeType method createAttribute.
public AttributeInterface createAttribute(Map<String, AttributeInterface> attributes) throws ApiException {
AttributeInterface attribute = null;
try {
AttributeInterface master = attributes.get(this.getType());
if (null == master) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute Type '" + this.getType() + "' does not exist");
}
attribute = (AttributeInterface) master.getAttributePrototype();
Pattern pattern = Pattern.compile("\\w+");
Matcher matcher = pattern.matcher(this.getName());
if (null == this.getName() || !matcher.matches()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid name '" + this.getName() + "' of Attribute Type '" + this.getType() + "'");
}
attribute.setName(this.getName());
attribute.setDescription(this.getDescription());
attribute.setRoles(this.toArray(this.getRoles()));
if (null != this.getSearchable())
attribute.setSearchable(this.getSearchable());
if (null != this.getIndexable())
attribute.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_TEXT);
attribute.setValidationRules((IAttributeValidationRules) this.getValidationRules());
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating attribute '{}'", this.getName(), t);
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Error creating attribute '" + this.getName() + "'");
}
return attribute;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeAddJaxbWidgetType.
private void testInvokeAddJaxbWidgetType(String newWidgetTypeCode, String widgetToClone, String customSingleGui, boolean expectedSuccess) throws Throwable {
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetToClone);
assertNotNull(widgetType);
WidgetType newWidgetType = widgetType.clone();
assertNull(this._widgetTypeManager.getWidgetType(newWidgetTypeCode));
newWidgetType.setCode(newWidgetTypeCode);
try {
JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(newWidgetType);
if (null != customSingleGui) {
jaxbWidgetType.setGui(customSingleGui);
}
this._apiWidgetTypeInterface.addWidgetType(jaxbWidgetType);
if (!expectedSuccess) {
fail();
}
WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(newWidgetTypeCode);
assertNotNull(extractedWidgetType);
assertEquals(newWidgetType.getConfig(), extractedWidgetType.getConfig());
assertEquals(newWidgetType.getMainGroup(), extractedWidgetType.getMainGroup());
assertEquals(newWidgetType.getTitles(), extractedWidgetType.getTitles());
assertEquals(newWidgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
assertFalse(extractedWidgetType.isLocked());
} catch (ApiException ae) {
if (expectedSuccess) {
fail();
}
} catch (Throwable t) {
throw t;
} finally {
List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(newWidgetTypeCode);
if (null != codes) {
for (int i = 0; i < codes.size(); i++) {
String code = codes.get(i);
this._guiFragmentManager.deleteGuiFragment(code);
}
}
this._widgetTypeManager.deleteWidgetType(newWidgetTypeCode);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeGetJaxbWidgetType.
private void testInvokeGetJaxbWidgetType(String widgetTypeCode) throws Throwable {
Properties properties = new Properties();
properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
properties.put("code", widgetTypeCode);
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
try {
JAXBWidgetType jaxbwt = this._apiWidgetTypeInterface.getWidgetType(properties);
assertNotNull(jaxbwt);
assertEquals(widgetTypeCode, jaxbwt.getCode());
assertEquals(widgetType.getTitles(), jaxbwt.getTitles());
} catch (ApiException ae) {
if (null != widgetType) {
fail();
}
} catch (Throwable t) {
throw t;
}
}
Aggregations