Search in sources :

Example 1 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class ApiWidgetTypeInterface method updateWidgetType.

public StringApiResponse updateWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    WidgetType widgetTypeToUpdate = null;
    List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
    List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
    try {
        widgetTypeToUpdate = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
        if (null == widgetTypeToUpdate) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " does not exists", Response.Status.CONFLICT);
        }
        WidgetType widgetType = jaxbWidgetType.getModifiedWidgetType(this.getWidgetTypeManager());
        this.checkAndSaveFragment(widgetType, jaxbWidgetType, false, response, addedFragments, updatedFragments);
        this.getWidgetTypeManager().updateWidgetType(widgetType.getCode(), widgetType.getTitles(), widgetType.getConfig(), widgetType.getMainGroup());
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        throw ae;
    } catch (Throwable t) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        _logger.error("Error updating widget type", t);
        throw t;
    }
    return response;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 2 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class ApiWidgetTypeInterface method getWidgetTypes.

public List<LinkedListItem> getWidgetTypes(Properties properties) throws Throwable {
    List<LinkedListItem> list = new ArrayList<LinkedListItem>();
    try {
        List<WidgetType> types = this.getWidgetTypeManager().getWidgetTypes();
        for (int i = 0; i < types.size(); i++) {
            WidgetType widgetType = types.get(i);
            String url = this.getApiResourceUrl(widgetType, properties.getProperty(SystemConstants.API_APPLICATION_BASE_URL_PARAMETER), properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER), (MediaType) properties.get(SystemConstants.API_PRODUCES_MEDIA_TYPE_PARAMETER));
            LinkedListItem item = new LinkedListItem();
            item.setCode(widgetType.getCode());
            item.setUrl(url);
            list.add(item);
        }
    } catch (Throwable t) {
        _logger.error("Error extracting list of widget types", t);
        throw t;
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) LinkedListItem(org.entando.entando.aps.system.services.api.model.LinkedListItem) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 3 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class ApiWidgetTypeInterface method getApiResourceUrl.

@Override
public String getApiResourceUrl(Object object, String applicationBaseUrl, String langCode, MediaType mediaType) {
    if (!(object instanceof WidgetType) || null == applicationBaseUrl || null == langCode) {
        return null;
    }
    WidgetType widgetType = (WidgetType) object;
    StringBuilder stringBuilder = new StringBuilder(applicationBaseUrl);
    // ?code=").append(widgetType.getCode());
    stringBuilder.append("api/rs/").append(langCode).append("/core/widgetType");
    if (null == mediaType || mediaType.equals(MediaType.APPLICATION_XML_TYPE)) {
        stringBuilder.append(".xml");
    } else {
        stringBuilder.append(".json");
    }
    stringBuilder.append("?code=").append(widgetType.getCode());
    return stringBuilder.toString();
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType)

Example 4 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class ApiWidgetTypeInterface method deleteWidgetType.

public void deleteWidgetType(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    try {
        WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(code);
        if (null == widgetType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type with code " + code + " does not exists", Response.Status.CONFLICT);
        }
        if (widgetType.isLocked()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type '" + code + "' is locked", Response.Status.CONFLICT);
        }
        List<IPage> referencedPages = this.getPageManager().getDraftWidgetUtilizers(code);
        if (null != referencedPages && !referencedPages.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Widget Type '" + code + "' is published into some pages", Response.Status.CONFLICT);
        }
        this.getWidgetTypeManager().deleteWidgetType(code);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting widget type throw api", t);
        throw t;
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 5 with WidgetType

use of org.entando.entando.aps.system.services.widgettype.WidgetType in project entando-core by entando.

the class JAXBWidgetType method getNewWidgetType.

public WidgetType getNewWidgetType(IWidgetTypeManager widgetTypeManager) {
    WidgetType type = new WidgetType();
    type.setCode(this.getCode());
    type.setTitles(this.getTitles());
    List<WidgetTypeParameter> parameters = this.getTypeParameters();
    if (null != parameters && !parameters.isEmpty()) {
        type.setTypeParameters(parameters);
        type.setAction("configSimpleParameter");
    } else {
        ApsProperties configuration = this.getConfig();
        String parentTypeCode = this.getParentTypeCode();
        if (null != parentTypeCode && null != configuration && !configuration.isEmpty()) {
            WidgetType parentType = widgetTypeManager.getWidgetType(parentTypeCode);
            type.setParentType(parentType);
            type.setConfig(configuration);
        }
    }
    type.setMainGroup(this.getMainGroup());
    // type.setLocked(this.isLocked());
    type.setPluginCode(this.getPluginCode());
    return type;
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetTypeParameter(org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)70 ApsProperties (com.agiletec.aps.util.ApsProperties)33 Widget (com.agiletec.aps.system.services.page.Widget)20 IPage (com.agiletec.aps.system.services.page.IPage)11 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)10 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 WidgetTypeParameter (org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter)5 ActionSupport (com.opensymphony.xwork2.ActionSupport)4 IManager (com.agiletec.aps.system.common.IManager)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Lang (com.agiletec.aps.system.services.lang.Lang)3 List (java.util.List)3 JAXBGuiFragment (org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment)3 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)3 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)2 SelectItem (com.agiletec.aps.util.SelectItem)2 Properties (java.util.Properties)2 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)2