Search in sources :

Example 31 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class WidgetTypeAction method saveUserWidget.

protected String saveUserWidget() {
    try {
        boolean isCopy = (null != this.getPageCode() && this.getPageCode().trim().length() > 0);
        String check = (isCopy) ? this.checkWidgetToCopy() : this.checkNewUserWidget();
        if (null != check) {
            return check;
        }
        WidgetType newType = null;
        Widget widgetToCopy = this.extractWidgetToCopy();
        if (null == widgetToCopy) {
            this.setReplaceOnPage(false);
            newType = this.createNewWidgetType();
            WidgetType parentType = this.getWidgetTypeManager().getWidgetType(this.getParentWidgetTypeCode());
            newType.setParentType(parentType);
            ApsProperties config = this.extractWidgetTypeConfig(parentType.getTypeParameters());
            newType.setConfig(config);
        } else {
            newType = this.createCopiedWidget(widgetToCopy);
        }
        // TODO CHECK MainGroup
        newType.setMainGroup(this.getMainGroup());
        this.getWidgetTypeManager().addWidgetType(newType);
        if (this.isReplaceOnPage()) {
            WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
            Widget widget = new Widget();
            widget.setType(type);
            IPage page = this.getPageManager().getDraftPage(this.getPageCode());
            page.getWidgets()[this.getFramePos()] = widget;
            this.getPageManager().updatePage(page);
            return "replaceOnPage";
        }
    } catch (Throwable t) {
        _logger.error("error in saveUserWidget", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 32 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class ApiCatalogDAO method buildService.

private void buildService(Map<String, ApiMethod> methods, Map<String, ApiService> services, List<String> invalidServices, ResultSet res) {
    String key = null;
    try {
        key = res.getString(1);
        String parentCode = res.getString(2);
        ApiMethod masterMethod = methods.get(parentCode);
        if (null != masterMethod) {
            ApsProperties description = new ApsProperties();
            description.loadFromXml(res.getString(3));
            ApsProperties parameters = new ApsProperties();
            parameters.loadFromXml(res.getString(4));
            String tag = res.getString(5);
            String[] freeParameters = null;
            String freeParamString = res.getString(6);
            if (null != freeParamString && freeParamString.trim().length() > 0) {
                ServiceExtraConfigDOM dom = new ServiceExtraConfigDOM(freeParamString);
                freeParameters = dom.extractFreeParameters();
            }
            boolean isActive = (1 == res.getInt(7)) ? true : false;
            boolean isHidden = (1 == res.getInt(8)) ? true : false;
            // boolean isMyEntando = (1 == res.getInt(9)) ? true : false;
            ApiService apiService = new ApiService(key, description, masterMethod, parameters, freeParameters, tag, !isHidden, isActive);
            boolean authRequired = (1 == res.getInt(10)) ? true : false;
            apiService.setRequiredAuth(authRequired);
            String requiredPermission = res.getString(11);
            if (null != requiredPermission && requiredPermission.trim().length() > 0) {
                apiService.setRequiredPermission(requiredPermission);
            }
            String requiredGroup = res.getString(12);
            if (null != requiredGroup && requiredGroup.trim().length() > 0) {
                apiService.setRequiredGroup(requiredGroup);
            }
            services.put(key, apiService);
        } else {
            invalidServices.add(key);
        }
    } catch (Throwable t) {
        _logger.error("Error building service - key '{}'", key, t);
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 33 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class ApiServiceInterface method createServiceInfo.

protected ServiceInfo createServiceInfo(ApiService service, String langCode, String defaultLangCode) {
    String description = service.getDescription().getProperty(langCode);
    if (null == description || description.trim().length() == 0) {
        description = service.getDescription().getProperty(defaultLangCode);
    }
    ServiceInfo smallService = new ServiceInfo(service.getKey(), description, service.getTag());
    String[] freeParameters = service.getFreeParameters();
    if (null != freeParameters && freeParameters.length > 0) {
        for (int i = 0; i < freeParameters.length; i++) {
            String freeParameter = freeParameters[i];
            ApiMethodParameter apiParameter = service.getMaster().getParameter(freeParameter);
            if (null != apiParameter) {
                ServiceParameterInfo spi = new ServiceParameterInfo(apiParameter);
                ApsProperties serviceParameters = service.getParameters();
                String defaultValue = (null != serviceParameters) ? serviceParameters.getProperty(freeParameter) : null;
                if (null != defaultValue) {
                    spi.setDefaultValue(defaultValue);
                    spi.setRequired(false);
                }
                smallService.addParameter(spi);
            }
        }
    }
    return smallService;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ApiMethodParameter(org.entando.entando.aps.system.services.api.model.ApiMethodParameter) ServiceParameterInfo(org.entando.entando.aps.system.services.api.model.ServiceParameterInfo) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 34 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class LabelServiceTest method testUpdateLabelGroup.

@Test
public void testUpdateLabelGroup() throws ApsSystemException {
    when(langManager.getDefaultLang()).thenReturn(lang);
    when(langManager.getAssignableLangs()).thenReturn(singletonList(lang));
    when(langManager.getLangs()).thenReturn(singletonList(lang));
    when(i18nManager.getLabelGroup(eq("lab"))).thenReturn(create(singletonMap("EN", "some_value")));
    final LabelDto label = new LabelDto("lab", singletonMap("EN", "another_value"));
    final LabelDto labelResult = labelService.updateLabelGroup(label);
    ArgumentCaptor<ApsProperties> captor = ArgumentCaptor.forClass(ApsProperties.class);
    verify(i18nManager, times(1)).getLabelGroup(eq("lab"));
    verify(i18nManager, times(1)).updateLabelGroup(eq("lab"), captor.capture());
    final ApsProperties value = captor.getValue();
    assertThat(value.getProperty("EN")).isEqualTo("another_value");
    assertThat(labelResult.getKey()).isEqualTo("lab");
    assertThat(labelResult.getTitles()).hasSize(1);
    assertThat(labelResult.getTitles()).containsOnly(entry("EN", "another_value"));
}
Also used : LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) ApsProperties(com.agiletec.aps.util.ApsProperties) Test(org.junit.Test)

Example 35 with ApsProperties

use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.

the class LabelServiceTest method testGetLabelsPagination.

@Test
public void testGetLabelsPagination() {
    RestListRequest request = new RestListRequest();
    Map<String, String> labelsMap = new HashMap<>();
    int pageSize = 5;
    int totalItems = 14;
    HashMap<String, ApsProperties> apsPropertiesMap = new HashMap();
    for (int i = 0; i < totalItems; i++) {
        labelsMap.put("it", "value");
        labelsMap.put("en", "value");
        apsPropertiesMap.put(String.valueOf(i), create(labelsMap));
    }
    when(i18nManager.getLabelGroups()).thenReturn(apsPropertiesMap);
    int page = 1;
    request.setPage(page);
    request.setPageSize(pageSize);
    PagedMetadata<LabelDto> labelGroups = labelService.getLabelGroups(request);
    assertThat(labelGroups.getBody()).hasSize(pageSize);
    assertThat(labelGroups.getTotalItems()).isEqualTo(totalItems);
    assertThat(labelGroups.getPage()).isEqualTo(page);
    page = 2;
    request.setPage(page);
    request.setPageSize(pageSize);
    labelGroups = labelService.getLabelGroups(request);
    assertThat(labelGroups.getBody()).hasSize(pageSize);
    assertThat(labelGroups.getTotalItems()).isEqualTo(totalItems);
    assertThat(labelGroups.getPage()).isEqualTo(page);
    page = 3;
    request.setPage(page);
    request.setPageSize(pageSize);
    labelGroups = labelService.getLabelGroups(request);
    assertThat(labelGroups.getBody()).hasSize(totalItems - (pageSize * (page - 1)));
    assertThat(labelGroups.getTotalItems()).isEqualTo(totalItems);
    assertThat(labelGroups.getPage()).isEqualTo(page);
}
Also used : HashMap(java.util.HashMap) RestListRequest(org.entando.entando.web.common.model.RestListRequest) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) Mockito.anyString(org.mockito.Mockito.anyString) ApsProperties(com.agiletec.aps.util.ApsProperties) Test(org.junit.Test)

Aggregations

ApsProperties (com.agiletec.aps.util.ApsProperties)157 Widget (com.agiletec.aps.system.services.page.Widget)62 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)35 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)28 HashMap (java.util.HashMap)22 IPage (com.agiletec.aps.system.services.page.IPage)18 Lang (com.agiletec.aps.system.services.lang.Lang)14 Test (org.junit.Test)12 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)10 Properties (java.util.Properties)9 RestServerError (org.entando.entando.aps.system.exception.RestServerError)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 Page (com.agiletec.aps.system.services.page.Page)8 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)8 List (java.util.List)8 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 ArrayList (java.util.ArrayList)6 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)6 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)5