use of com.developmentontheedge.be5.metadata.model.PageCustomization in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readCustomizations.
/**
* Used with customizations (module), entity, query, operation and static page.
*/
@SuppressWarnings("unchecked")
private void readCustomizations(final Map<String, Object> serialized, final BeVectorCollection<?> target, boolean replace) {
if (project == null)
throw new IllegalStateException();
final Map<String, Object> serializedCustomizations = (Map<String, Object>) serialized.get("customizations");
if (serializedCustomizations == null || serializedCustomizations.isEmpty())
return;
final BeVectorCollection<PageCustomization> customizations = replace ? new PageCustomizations(target) : target.getOrCreateCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
try {
for (final String name : serializedCustomizations.keySet()) {
final Map<String, Object> content = (Map<String, Object>) serializedCustomizations.get(name);
final List<String> splitted = StreamEx.split(name, "\\.").toList();
final String type;
final String domain;
if (splitted.size() == 1) {
type = "";
domain = splitted.get(0);
} else {
type = splitted.get(splitted.size() - 1);
splitted.remove(splitted.size() - 1);
domain = String.join(".", splitted);
}
final PageCustomization customization = new PageCustomization(type, domain, customizations);
customization.setCode((String) content.get(TAG_CODE));
customization.setOriginModuleName(project.getProjectOrigin());
DataElementUtils.saveQuiet(customization);
}
} catch (Exception e) {
loadContext.addWarning(new ReadException(e, target, project.getLocation()));
}
if (replace)
DataElementUtils.save(customizations);
}
use of com.developmentontheedge.be5.metadata.model.PageCustomization in project be5 by DevelopmentOnTheEdge.
the class YamlSerializer method serializeCustomizations.
private Map<String, Object> serializeCustomizations(final BeVectorCollection<?> parent) {
final Map<String, Object> serializedCustomizations = map();
final BeModelCollection<PageCustomization> customiazations = parent.getCollection(PageCustomization.CUSTOMIZATIONS_COLLECTION, PageCustomization.class);
if (customiazations != null) {
final String projectOrigin = parent.getProject().getProjectOrigin();
for (final PageCustomization customization : customiazations) {
if (!projectOrigin.equals(customization.getOriginModuleName()))
continue;
final String name = customization.getDomain() + "." + customization.getType();
final Map<String, Object> serializedCustomization = map();
final List<String> serializedRoles = list(customization.getRoles());
if (!serializedRoles.isEmpty())
serializedCustomization.put(ATTR_ROLES, serializedRoles);
serializedCustomization.put(TAG_CODE, customization.getCode());
serializedCustomizations.put(name, serializedCustomization);
}
}
return serializedCustomizations;
}
use of com.developmentontheedge.be5.metadata.model.PageCustomization in project be5 by DevelopmentOnTheEdge.
the class Project method getContext.
/**
* Creates and returns FreeMarker context for given element
* @param element to create context for (can be null)
* @return
*/
public Map<String, Object> getContext(TemplateElement element) {
Map<String, Object> context = new HashMap<>();
BeModelElement parent = element;
while (parent != null) {
if (parent instanceof PageCustomization) {
context.put("customization", parent);
} else if (parent instanceof Query) {
context.put("query", parent);
} else if (parent instanceof Operation) {
context.put("operation", parent);
} else if (parent instanceof Entity) {
context.put("entity", parent);
} else if (parent instanceof Module) {
context.put("module", parent);
}
parent = parent.getOrigin();
}
for (String name : getPropertyNames()) {
context.put(name, getProperty(name));
}
BeConnectionProfile profile = getConnectionProfile();
if (profile != null) {
for (String name : profile.getPropertyNames()) {
context.put(name, profile.getProperty(name));
}
}
return context;
}
Aggregations