use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DocumentJavaFieldReader method read.
@Override
public void read(AtlasInternalSession session) throws AtlasException {
try {
Field sourceField = session.head().getSourceField();
Method getter = null;
if (sourceField.getFieldType() == null && (sourceField instanceof JavaField || sourceField instanceof JavaEnumField)) {
getter = resolveGetMethod(sourceDocument, sourceField);
if (getter == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unable to auto-detect sourceField type path=%s docId=%s", sourceField.getPath(), sourceField.getDocId()), sourceField.getPath(), AuditStatus.WARN, null);
return;
}
Class<?> returnType = getter.getReturnType();
sourceField.setFieldType(conversionService.fieldTypeFromClass(returnType));
if (LOG.isTraceEnabled()) {
LOG.trace("Auto-detected sourceField type p=" + sourceField.getPath() + " t=" + sourceField.getFieldType());
}
}
populateSourceFieldValue(session, sourceField, sourceDocument, getter);
if (LOG.isDebugEnabled()) {
LOG.debug("Processed input field sPath=" + sourceField.getPath() + " sV=" + sourceField.getValue() + " sT=" + sourceField.getFieldType() + " docId: " + sourceField.getDocId());
}
} catch (Exception e) {
throw new AtlasException(e);
}
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DocumentJavaFieldWriter method getClassForField.
private Class<?> getClassForField(Field field, SegmentContext segmentContext, Object parentObject, boolean unwrapCollectionType) throws AtlasException {
if (LOG.isDebugEnabled()) {
LOG.debug("Looking up class to use for segment: " + segmentContext + "\n\tparentObject: " + parentObject);
}
Class<?> clz = null;
if (LOG.isDebugEnabled()) {
LOG.debug("Looking for configured class for field: " + field + ".");
}
String className = null;
if (field instanceof JavaField) {
className = ((JavaField) field).getClassName();
} else if (field instanceof JavaEnumField) {
className = ((JavaEnumField) field).getClassName();
}
if (className != null) {
try {
clz = className == null ? null : Class.forName(className);
} catch (Exception e) {
throw new AtlasException("Could not find class for '" + className + "', for segment: " + segmentContext + ", on field: " + field, e);
}
}
if (clz == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Couldn't find class on field. Looking for configured class for segment: " + segmentContext + ".");
}
String normalizedSegment = AtlasPath.removeCollectionIndexes(segmentContext.getSegmentPath());
clz = this.classesForFields.get(normalizedSegment);
}
Type clzType = null;
if (clz == null) {
// attempt to determine it from the parent object.
if (LOG.isDebugEnabled()) {
LOG.debug("Couldn't find configured class for segment: " + segmentContext + ", looking up getter method.");
}
Method m = null;
try {
String methodName = "get" + JavaWriterUtil.capitalizeFirstLetter(AtlasPath.cleanPathSegment(segmentContext.getSegment()));
m = ClassHelper.detectGetterMethod(parentObject.getClass(), methodName);
} catch (NoSuchMethodException e) {
// it's ok, we didnt find a getter.
if (LOG.isDebugEnabled()) {
LOG.debug("Couldn't find getter method for segment: " + segmentContext, e);
}
}
clz = m == null ? null : m.getReturnType();
clzType = m.getGenericReturnType();
}
if (clz == null) {
throw new AtlasException("Could not create object, can't find class to instantiate for segment: " + segmentContext);
}
if (unwrapCollectionType) {
clz = unwrapCollectionType(field, segmentContext, parentObject, clz, clzType);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Found class '" + clz.getName() + "' to use for segment: " + segmentContext);
}
return clz;
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class ClassInspectionService method inspectField.
private JavaField inspectField(ClassLoader classLoader, Field f, Set<String> cachedClasses, String pathPrefix) {
JavaField s = AtlasJavaModelFactory.createJavaField();
Class<?> clazz = f.getType();
s.setName(f.getName());
if (pathPrefix != null && pathPrefix.length() > 0) {
s.setPath(pathPrefix + AtlasPath.PATH_SEPARATOR + f.getName());
} else {
s.setPath(f.getName());
}
if (isMapList(clazz.getCanonicalName())) {
s.setCollectionType(CollectionType.MAP);
}
if (clazz.isArray()) {
s.setCollectionType(CollectionType.ARRAY);
s.setArrayDimensions(detectArrayDimensions(clazz));
clazz = detectArrayClass(clazz);
} else if (isFieldList(clazz.getCanonicalName())) {
s.setCollectionType(CollectionType.LIST);
s.setCollectionClassName(clazz.getCanonicalName());
try {
clazz = detectListClass(classLoader, f);
if (clazz == null) {
s.setStatus(FieldStatus.ERROR);
return s;
}
} catch (ClassCastException | ClassNotFoundException cce) {
LOG.debug("Error detecting inner listClass: " + cce.getMessage() + " for field: " + f.getName(), cce);
s.setStatus(FieldStatus.ERROR);
return s;
}
}
s.setFieldType(getConversionService().fieldTypeFromClass(clazz));
if (getConversionService().isPrimitive(clazz) || getConversionService().isBoxedPrimitive(clazz)) {
s.setPrimitive(true);
s.setStatus(FieldStatus.SUPPORTED);
} else if (s.getFieldType() != FieldType.COMPLEX) {
s.setPrimitive(false);
s.setStatus(FieldStatus.SUPPORTED);
} else {
s.setPrimitive(false);
Class<?> complexClazz = null;
JavaClass tmpField = convertJavaFieldToJavaClass(s);
s = tmpField;
if (clazz.getCanonicalName() == null) {
s.setStatus(FieldStatus.UNSUPPORTED);
} else if (!cachedClasses.contains(clazz.getCanonicalName())) {
try {
complexClazz = classLoader.loadClass(clazz.getCanonicalName());
cachedClasses.add(clazz.getCanonicalName());
inspectClass(classLoader, complexClazz, tmpField, cachedClasses, s.getPath());
if (tmpField.getStatus() == null) {
s.setStatus(FieldStatus.SUPPORTED);
}
} catch (ClassNotFoundException cnfe) {
s.setStatus(FieldStatus.NOT_FOUND);
}
} else {
s.setStatus(FieldStatus.CACHED);
}
}
s.setClassName(clazz.getCanonicalName());
s.setSynthetic(f.isSynthetic());
Annotation[] annotations = f.getAnnotations();
if (annotations != null) {
for (Annotation a : annotations) {
if (s.getAnnotations() == null) {
s.setAnnotations(new StringList());
}
s.getAnnotations().getString().add(a.annotationType().getCanonicalName());
}
}
if (s.getModifiers() == null) {
s.setModifiers(new ModifierList());
}
s.getModifiers().getModifier().addAll(detectModifiers(f.getModifiers()));
List<String> pTypes = detectParameterizedTypes(f, false);
if (pTypes != null) {
if (s.getParameterizedTypes() == null) {
s.setParameterizedTypes(new StringList());
}
s.getParameterizedTypes().getString().addAll(pTypes);
}
populateGetterSetter(clazz, f, s);
return s;
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class BaseDocumentWriterTest method write.
protected void write(String path, StateEnumClassLong targetValue) throws AtlasException {
Field field = createEnumField(path, targetValue);
setTargetValue(targetValue);
write(field);
}
use of io.atlasmap.v2.Field in project syndesis-qe by syndesisio.
the class UiComplexSteps method dbToDbIntegrationWithPeriodMs.
@Given("^db to db \"([^\"]*)\" integration with period (\\d+) ms$")
public void dbToDbIntegrationWithPeriodMs(String integrationName, int ms) throws IOException {
final Connection dbConnection = connectionsEndpoint.get(getDbConnectionId());
final Connector dbConnector = connectorsEndpoint.get("sql");
final String sqlStartQuery = "SELECT * FROM CONTACT";
final String sqlFinishQuery = "INSERT INTO TODO(task, completed) VALUES (:#TASK, 2)";
final String datamapperTemplate = "db-db.json";
// 1. @Then("^create start DB periodic sql invocation action step with query \"([^\"]*)\" and period \"([^\"]*)\" ms")
final Action dbAction1 = TestUtils.findConnectorAction(dbConnector, "sql-start-connector");
final Map<String, String> properties1 = TestUtils.map("query", sqlStartQuery, "schedulerPeriod", ms);
final ConnectorDescriptor connectorDescriptor1 = getConnectorDescriptor(dbAction1, properties1, dbConnection.getId().get());
// to be reported: period is not part of .json step (when checked via browser).
final Step dbStep1 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction1).configuredProperties(properties1).build();
steps.getStepDefinitions().add(new StepDefinition(dbStep1, connectorDescriptor1));
// 2.A @And("start mapper definition with name: \"([^\"]*)\"")
String mapperName = "mapping 1";
final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).name(mapperName).build();
steps.getStepDefinitions().add(new StepDefinition(mapperStep, new DataMapperDefinition()));
// 2.B @Then("MAP using Step (\\d+) and field \"([^\"]*)\" to \"([^\"]*)\"")
int fromStep = 1;
String fromField = "first_name";
String toField = "TASK";
DataMapperStepDefinition newDmStep = new DataMapperStepDefinition();
newDmStep.setFromStep(fromStep);
newDmStep.setInputFields(Arrays.asList(fromField));
newDmStep.setOutputFields(Arrays.asList(toField));
newDmStep.setMappingType(MappingType.MAP);
newDmStep.setStrategy(null);
steps.getLastStepDefinition().getDataMapperDefinition().get().getDataMapperStepDefinition().add(newDmStep);
// 3. @Then("^create finish DB invoke sql action step with query \"([^\"]*)\"")
final Action dbAction2 = TestUtils.findConnectorAction(dbConnector, "sql-connector");
final Map<String, String> properties2 = TestUtils.map("query", sqlFinishQuery);
final ConnectorDescriptor connectorDescriptor2 = getConnectorDescriptor(dbAction2, properties2, dbConnection.getId().get());
final Step dbStep2 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction2).configuredProperties(properties2).build();
steps.getStepDefinitions().add(new StepDefinition(dbStep2, connectorDescriptor2));
// 4. @When("^create integration with name: \"([^\"]*)\"")
processMapperSteps();
Integration integration = new Integration.Builder().steps(steps.getSteps()).name(integrationName).description("Awkward UI integration.").build();
log.info("Creating integration {}", integration.getName());
String integrationId = integrationsEndpoint.create(integration).getId().get();
log.info("Publish integration with ID: {}", integrationId);
publishIntegration(integrationId);
log.debug("Flushing used steps");
steps.flushStepDefinitions();
// 5. @Then("^wait for integration with name: \"([^\"]*)\" to become active")
final List<Integration> integrations = integrationsEndpoint.list().stream().filter(item -> item.getName().equals(integrationName)).collect(Collectors.toList());
final long start = System.currentTimeMillis();
// wait for activation
log.info("Waiting until integration \"{}\" becomes active. This may take a while...", integrationName);
integrationOverviewEndpoint = new IntegrationOverviewEndpoint(integrationId);
final IntegrationOverview integrationOverview = integrationOverviewEndpoint.getOverview();
final boolean activated = TestUtils.waitForPublishing(integrationOverviewEndpoint, integrationOverview, TimeUnit.MINUTES, 10);
Assertions.assertThat(activated).isEqualTo(true);
log.info("Integration pod has been started. It took {}s to build the integration.", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start));
}
Aggregations