use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.
the class FileJSONTableWizardPage method createControl.
/**
* Create the first composite, addComponentsAndControls and initialize TableWizardPage.
*
* @see IDialogPage#createControl(Composite)
*/
public void createControl(final Composite parent) {
final AbstractForm.ICheckListener listener = new AbstractForm.ICheckListener() {
public void checkPerformed(final AbstractForm source) {
if (source.isStatusOnError()) {
FileJSONTableWizardPage.this.setPageComplete(false);
setErrorMessage(source.getStatus());
} else {
FileJSONTableWizardPage.this.setPageComplete(isRepositoryObjectEditable);
setErrorMessage(null);
setMessage(source.getStatus(), source.getStatusLevel());
}
}
};
Composite theForm = null;
Connection connection = null;
if (metadataTable.getNamespace() != null) {
if (metadataTable.getNamespace() instanceof Package) {
Package pkg = (Package) metadataTable.getNamespace();
if (!pkg.getDataManager().isEmpty()) {
connection = (Connection) pkg.getDataManager().get(0);
}
}
}
theForm = (Composite) new JsonSwitch() {
public Object caseJSONFileConnection(final JSONFileConnection object) {
JSONFileConnection jsonFileConnection = (JSONFileConnection) connectionItem.getConnection();
boolean isInputModel = jsonFileConnection.isInputModel();
if (isInputModel) {
JSONFileStep3Form xmlFileStep3Form = new JSONFileStep3Form(parent, connectionItem, metadataTable, null, TableHelper.getTableNames(object, metadataTable.getLabel()));
xmlFileStep3Form.setReadOnly(!isRepositoryObjectEditable);
xmlFileStep3Form.setListener(listener);
return xmlFileStep3Form;
} else {
JSONFileOutputStep3Form xmlFileOutputStep3Form = new JSONFileOutputStep3Form(parent, connectionItem, metadataTable, TableHelper.getTableNames(object, metadataTable.getLabel()));
xmlFileOutputStep3Form.setReadOnly(!isRepositoryObjectEditable);
xmlFileOutputStep3Form.setListener(listener);
return xmlFileOutputStep3Form;
}
}
}.doSwitch(connection);
setControl(theForm);
}
use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.
the class JSONDragAndDropHandler method getTableJSONMappingValue.
private List<Map<String, Object>> getTableJSONMappingValue(Connection connection) {
List<Map<String, Object>> tableInfo = new ArrayList<Map<String, Object>>();
if (connection instanceof JSONFileConnection) {
JSONFileConnection jsonConnection = (JSONFileConnection) connection;
if (jsonConnection.isInputModel()) {
EList objectList = jsonConnection.getSchema();
JSONXPathLoopDescriptor jsonDesc = (JSONXPathLoopDescriptor) objectList.get(0);
List<SchemaTarget> schemaTargets = jsonDesc.getSchemaTargets();
tableInfo.clear();
String tagName;
for (int j = 0; j < schemaTargets.size(); j++) {
SchemaTarget schemaTarget = schemaTargets.get(j);
if (schemaTarget.getTagName() != null && !schemaTarget.getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$
tagName = "" + schemaTarget.getTagName().trim().replaceAll(" ", "_");
tagName = MetadataToolHelper.validateColumnName(tagName, j);
Map<String, Object> map = new HashMap<String, Object>();
//$NON-NLS-1$
map.put("SCHEMA_COLUMN", tagName);
String xpath = schemaTarget.getRelativeXPathQuery();
String flag = jsonDesc.getFlag();
if (flag != null && flag.equals(ConvertJSONString.ROOT)) {
if (xpath.startsWith("root/")) {
xpath = xpath.replaceFirst("root/", "");
}
} else if (flag != null && flag.equals(ConvertJSONString.ROOT_OBJECT)) {
if (xpath.startsWith("object/")) {
xpath = xpath.replaceFirst("object/", "");
}
}
//$NON-NLS-1$
map.put("QUERY", TalendQuoteUtils.addQuotes(xpath));
tableInfo.add(map);
}
}
}
}
return tableInfo;
}
use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.
the class JSONDragAndDropHandler method filterNeededComponents.
@Override
public List<IComponent> filterNeededComponents(Item item, RepositoryNode seletetedNode, ERepositoryObjectType type) {
List<IComponent> neededComponents = new ArrayList<IComponent>();
if (!(item instanceof JSONFileConnectionItem)) {
return neededComponents;
}
IComponentsService service = (IComponentsService) GlobalServiceRegister.getDefault().getService(IComponentsService.class);
Set<IComponent> components = service.getComponentsFactory().getComponents();
JSONFileConnection connection = (JSONFileConnection) ((JSONFileConnectionItem) item).getConnection();
for (IComponent component : components) {
if (!connection.isInputModel()) {
if (isValid(item, type, seletetedNode, component, "JSONOUTPUT") && !neededComponents.contains(component)) {
neededComponents.add(component);
}
} else {
if (isValid(item, type, seletetedNode, component, JSON) && !neededComponents.contains(component)) {
neededComponents.add(component);
}
}
}
// type);
return neededComponents;
}
use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.
the class CreateJSONSchemaAction method doRun.
@Override
protected void doRun() {
if (repositoryNode == null) {
repositoryNode = getCurrentRepositoryNode();
}
JSONFileConnection connection = null;
MetadataTable metadataTable = null;
boolean creation = false;
if (repositoryNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
String metadataTableLabel = (String) repositoryNode.getProperties(EProperties.LABEL);
JSONFileConnectionItem item = null;
if (nodeType == ERepositoryObjectType.METADATA_CON_TABLE) {
item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
connection = (JSONFileConnection) item.getConnection();
metadataTable = TableHelper.findByLabel(connection, metadataTableLabel);
creation = false;
} else if (nodeType == JSONRepositoryNodeType.JSON) {
item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
connection = (JSONFileConnection) item.getConnection();
metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
String nextId = ProxyRepositoryFactory.getInstance().getNextId();
metadataTable.setId(nextId);
metadataTable.setLabel(getStringIndexed(metadataTable.getLabel()));
RecordFile record = (RecordFile) ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
if (record != null) {
// hywang
PackageHelper.addMetadataTable(metadataTable, record);
} else {
RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
ConnectionHelper.addPackage(newrecord, connection);
PackageHelper.addMetadataTable(metadataTable, newrecord);
}
creation = true;
} else {
return;
}
initContextMode(item);
openJSONSchemaWizard(item, metadataTable, false, creation);
}
}
use of org.talend.repository.model.json.JSONFileConnection in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method createContextParameters.
private static List<IContextParameter> createContextParameters(ConnectionItem connectionItem, Set<IConnParamName> paramSet) {
if (connectionItem == null) {
return null;
}
final String label = convertContextLabel(connectionItem.getProperty().getLabel());
Connection conn = connectionItem.getConnection();
List<IContextParameter> varList = null;
if (conn instanceof JSONFileConnection) {
varList = getJSONFileVariables(label, (JSONFileConnection) conn);
}
return varList;
}
Aggregations