use of io.atlasmap.v2.Document in project atlasmap by atlasmap.
the class JsonModule method processSourceFieldMapping.
@Override
public void processSourceFieldMapping(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
JsonFieldReader reader = session.getFieldReader(getDocId(), JsonFieldReader.class);
if (reader == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Source document '%s' doesn't exist", getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
return;
}
reader.read(session);
if (sourceField.getActions() != null && sourceField.getActions().getActions() != null) {
getFieldActionService().processActions(sourceField.getActions(), sourceField);
}
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processSourceFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue());
}
}
use of io.atlasmap.v2.Document in project atlasmap by atlasmap.
the class InstanceInspector method inspect.
public void inspect(Document document) {
xmlDocument.setFields(new Fields());
parseDocument(document.getDocumentElement());
}
use of io.atlasmap.v2.Document in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectFlatPrimitiveNoRoot.
@Test
public void inspectFlatPrimitiveNoRoot() throws Exception {
final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/flatprimitive-base-unrooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(instance);
assertNotNull(document);
assertEquals(5, document.getFields().getField().size());
List<Field> fields = document.getFields().getField();
JsonField field = (JsonField) fields.get(0);
assertEquals("booleanField", field.getName());
assertEquals("/booleanField", field.getPath());
assertEquals(FieldType.BOOLEAN, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(1);
assertEquals("stringField", field.getName());
assertEquals("/stringField", field.getPath());
assertEquals(FieldType.STRING, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(2);
assertEquals("numberField", field.getName());
assertEquals("/numberField", field.getPath());
assertEquals(FieldType.NUMBER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(3);
assertEquals("intField", field.getName());
assertEquals("/intField", field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(4);
assertEquals("nullField", field.getName());
assertEquals("/nullField", field.getPath());
assertEquals(FieldType.NONE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
use of io.atlasmap.v2.Document in project xwiki-platform by xwiki.
the class DefaultEntityResourceActionLister method initialize.
@Override
public void initialize() throws InitializationException {
// Parse the Struts config file (struts-config.xml) to extract all available actions
List<String> actionNames = new ArrayList<>();
SAXBuilder builder = new SAXBuilder();
// Make sure we don't require an Internet Connection to parse the Struts config file!
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
// Step 1: Get a stream on the Struts config file if it exists
InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource());
if (strutsConfigStream != null) {
// Step 2: Parse the Strust config file, looking for action names
Document document;
try {
document = builder.build(strutsConfigStream);
} catch (JDOMException | IOException e) {
throw new InitializationException(String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e);
}
Element mappingElement = document.getRootElement().getChild("action-mappings");
for (Element element : mappingElement.getChildren("action")) {
// We extract the action name from the path mapping. Note that we cannot use the "name" attribute since
// it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its
// "name" element value.
actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/"));
}
}
this.strutsActionNames = actionNames;
}
use of io.atlasmap.v2.Document in project coprhd-controller by CoprHD.
the class ServiceCatalogBuilder method build.
/**
* Parses xml file to ServiceCatalog with Jdom
*
* @param xmlFile
* The instance of xml file
* @return instance of ServiceCatalog
*/
public static ServiceCatalog build(final File xmlFile) {
String fileName = xmlFile.getName().trim().toLowerCase();
// remove suffix
if (fileName.endsWith(Constants.XML_FILE_SUFFIX)) {
fileName = fileName.substring(0, fileName.length() - Constants.XML_FILE_SUFFIX.length() - 1);
} else {
throw new IllegalArgumentException("API file is not xml format: " + fileName);
}
// filter name
int separatorIndex = fileName.indexOf(Constants.NAME_STRING_SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalArgumentException("API file name should split with " + Constants.NAME_STRING_SEPARATOR + " actually: " + fileName);
}
String serviceName = fileName.substring(0, separatorIndex);
String version = fileName.substring(separatorIndex + 1, fileName.length());
Document document;
try {
document = new SAXBuilder().build(xmlFile);
} catch (Exception ex) {
throw new IllegalArgumentException("Invalid XML file:\n " + xmlFile.getAbsolutePath(), ex);
}
if (document == null) {
return null;
}
// Navigates to resource tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> resourceList = document.getRootElement().getChild(Constants.REST_NODE).getChild(Constants.RESOURCES_NODE).getChildren();
// Navigates to element tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> elementList = document.getRootElement().getChild(Constants.DATA_NODE).getChild(Constants.DATA_SCHEMA_NODE).getChild(Constants.ELEMENTS_NODE).getChildren();
return new ServiceCatalog(parseResource(resourceList), parseElement(elementList), serviceName, version);
}
Aggregations