use of com.developmentontheedge.be5.metadata.exception.ReadException 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.exception.ReadException 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.exception.ReadException in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method readConnectionProfiles.
private void readConnectionProfiles(BeConnectionProfileType type, BeConnectionProfilesRoot target) throws ReadException {
Path connectionProfilesFile = getFileSystem().getConnectionProfilesFile(type);
if (target.getProject().isModuleProject() && !Files.exists(connectionProfilesFile))
return;
if (type == BeConnectionProfileType.LOCAL && !Files.exists(connectionProfilesFile)) {
target.put(new BeConnectionProfiles(BeConnectionProfileType.LOCAL, target));
return;
}
new ConnectionProfilesDeserializer(connectionProfilesFile, type, target).deserialize();
}
use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.
the class YamlDeserializer method reloadForms.
public JavaScriptForms reloadForms(final Path path, final Module target) throws ReadException {
final JavaScriptForms forms = new JavaScriptForms(target);
final FormsDeserializer deserializer = new FormsDeserializer(path, forms);
deserializer.deserialize();
DataElementUtils.saveQuiet(forms);
return forms;
}
use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.
the class ProjectFileSystem method read.
public static String read(final Path file) throws ReadException {
if (!Files.exists(file)) {
throw new ReadException(file, ReadException.LEE_NOT_FOUND);
}
if (!Files.isRegularFile(file)) {
throw new ReadException(file, ReadException.LEE_NOT_A_FILE);
}
final byte[] bytes;
try {
bytes = readBytes(file);
} catch (Exception e) {
throw new ReadException(e, file, ReadException.LEE_UNREADABLE);
}
ByteBuffer buffer = ByteBuffer.wrap(bytes);
CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
decoder.onMalformedInput(CodingErrorAction.REPORT);
decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
char[] resultArray = new char[(int) (bytes.length * decoder.maxCharsPerByte() + 1)];
CharBuffer decoded = CharBuffer.wrap(resultArray);
CoderResult result = decoder.decode(buffer, decoded, true);
try {
if (!result.isUnderflow())
result.throwException();
result = decoder.flush(decoded);
if (!result.isUnderflow())
result.throwException();
} catch (UnmappableCharacterException e) {
throw new ReadException(new Exception("Unmappable character at " + calcPosition(decoded)), file, ReadException.LEE_ENCODING_ERROR);
} catch (CharacterCodingException e) {
throw new ReadException(new Exception("Malformed character at " + calcPosition(decoded)), file, ReadException.LEE_ENCODING_ERROR);
}
int start = 0;
if (// Ignore BOM
resultArray.length > 0 && resultArray[0] == '\uFEFF')
start++;
return new String(resultArray, start, decoded.position() - start);
}
Aggregations