use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method reloadEntity.
public Entity reloadEntity(final Entity oldEntity) throws ReadException {
this.fileSystem = new ProjectFileSystem(oldEntity.getProject());
this.setProject(oldEntity.getProject());
final Entity entity = this.readEntity(oldEntity.getModule(), oldEntity.getName());
if (oldEntity.getPrototype() != null) {
@SuppressWarnings("unchecked") final BeModelCollection<BeModelElement> prototype = (BeModelCollection<BeModelElement>) oldEntity.getPrototype();
entity.merge(prototype, true, true);
}
EntitiesFactory.addToModule(entity, oldEntity.getModule());
return entity;
}
use of com.developmentontheedge.be5.metadata.model.Entity 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.Entity in project be5 by DevelopmentOnTheEdge.
the class MassChangeTest method testMassChange.
@Test
public void testMassChange() {
Project project = new Project("test");
Entity entity = new Entity("entity", project.getApplication(), EntityType.TABLE);
DataElementUtils.save(entity);
Query queryToChange = new Query("queryToChange", entity);
DataElementUtils.save(queryToChange);
Query query = new Query("query", entity);
DataElementUtils.save(query);
MassChange mc = new MassChange("Query[name*=\"Change\"]", project.getApplication().getMassChangeCollection(), Collections.singletonMap("type", QueryType.D2));
assertEquals("type", mc.getPropertiesString());
assertEquals("Query[name*=Change]", mc.getSelectorString());
DataElementUtils.save(mc);
assertEquals(QueryType.D1, queryToChange.getType());
assertEquals(QueryType.D1, query.getType());
LoadContext context = new LoadContext();
project.applyMassChanges(context);
context.check();
assertEquals(QueryType.D2, entity.getQueries().get("queryToChange").getType());
assertEquals(QueryType.D1, entity.getQueries().get("query").getType());
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadQueryOperation.
@Test
public void testWriteReadQueryOperation() throws Exception {
final Project project = new Project("TestProject");
final Module module = project.getApplication();
DataElementUtils.saveQuiet(module);
final Entity table = new Entity("table", module, EntityType.TABLE);
DataElementUtils.saveQuiet(table);
final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
DataElementUtils.saveQuiet(op);
final Query query = new Query("q", table);
DataElementUtils.saveQuiet(query);
query.getOperationNames().add("op");
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project readProject = Serialization.load(tempFolder);
final Entity readEntity = readProject.getApplication().getEntity("table");
assertEquals("op", readEntity.getQueries().get("q").getOperationNames().getValuesArray()[0]);
FileUtils.deleteRecursively(tempFolder);
}
use of com.developmentontheedge.be5.metadata.model.Entity in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadLocalizations.
@Test
public void testWriteReadLocalizations() throws Exception {
final Project project = new Project("test");
final Localizations localizations = project.getApplication().getLocalizations();
localizations.addLocalization("en", "entity", Arrays.asList("topic"), "hello", "Hello!");
localizations.addLocalization("de", "entity", Arrays.asList("topic", "topic2"), "hello", "Guten Tag!");
localizations.addLocalization("it", "entity", Arrays.asList("topic2"), "hello", "Buon giorno!");
final Path tempFolder = Files.createTempDirectory("be4-temp");
Serialization.save(project, tempFolder);
final Project project2 = Serialization.load(tempFolder);
final Localizations localizations2 = project2.getApplication().getLocalizations();
assertEquals("Hello!", localizations2.get("en").get("entity").elements().iterator().next().getValue());
assertEquals("Guten Tag!", localizations2.get("de").get("entity").elements().iterator().next().getValue());
assertEquals("Buon giorno!", localizations2.get("it").get("entity").elements().iterator().next().getValue());
FileUtils.deleteRecursively(tempFolder);
}
Aggregations