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;
}
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);
}
}
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;
}
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"));
}
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);
}
Aggregations