use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore.Parameters.Parameter in project hale by halestudio.
the class DataStoreComplexType method toDOM.
/**
* @see eu.esdihumboldt.hale.common.core.io.ComplexValueType#toDOM(java.lang.Object)
*/
@Override
public Element toDOM(DataStore dataStore) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element dataStoreEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "DataStore");
dataStoreEl.setPrefix(APP_SCHEMA_PREFIX);
if (dataStore != null) {
if (dataStore.getId() != null && !dataStore.getId().trim().isEmpty()) {
Element idEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "id");
idEl.setPrefix(APP_SCHEMA_PREFIX);
dataStoreEl.appendChild(idEl);
} else {
// TODO: generate unique id
}
if (dataStore.getParameters() != null) {
List<Parameter> parameters = dataStore.getParameters().getParameter();
if (parameters.size() > 0) {
Element paramsEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "parameters");
for (Parameter param : parameters) {
Element paramEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "Parameter");
Element paramNameEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "name");
paramNameEl.setTextContent(param.getName());
Element paramValueEl = doc.createElementNS(APP_SCHEMA_NAMESPACE, "value");
paramValueEl.setTextContent(param.getValue());
paramEl.appendChild(paramNameEl);
paramEl.appendChild(paramValueEl);
paramsEl.appendChild(paramEl);
}
dataStoreEl.appendChild(paramsEl);
}
}
}
return dataStoreEl;
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore.Parameters.Parameter in project hale by halestudio.
the class AppSchemaMappingGenerator method applyDataStoreConfig.
private void applyDataStoreConfig() {
if (dataStore != null && dataStore.getParameters() != null) {
DataStore targetDS = mappingWrapper.getDefaultDataStore();
List<Parameter> inputParameters = dataStore.getParameters().getParameter();
List<Parameter> targetParameters = targetDS.getParameters().getParameter();
// update destination parameters
for (Parameter inputParam : inputParameters) {
boolean updated = false;
for (Parameter targetParam : targetParameters) {
if (inputParam.getName().equals(targetParam.getName())) {
targetParam.setValue(inputParam.getValue());
updated = true;
break;
}
}
if (!updated) {
// parameter was not already present: add it to the list
targetParameters.add(inputParam);
}
}
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore.Parameters.Parameter in project hale by halestudio.
the class AppSchemaFileWriterTest method createDataStoreParam.
private DataStore createDataStoreParam() {
DataStore dataStoreParam = new DataStore();
dataStoreParam.setParameters(new Parameters());
Parameter hostParam = new Parameter();
hostParam.setName("host");
hostParam.setValue("localhost");
Parameter dbParam = new Parameter();
dbParam.setName("database");
dbParam.setValue("postgres");
Parameter userParam = new Parameter();
userParam.setName("user");
userParam.setValue("postgres");
Parameter passwdParam = new Parameter();
passwdParam.setName("passwd");
passwdParam.setValue("postgres");
Parameter dbtypeParam = new Parameter();
dbtypeParam.setName("dbtype");
dbtypeParam.setValue("postgis");
dataStoreParam.getParameters().getParameter().addAll(Arrays.asList(hostParam, dbParam, dbtypeParam, userParam, passwdParam));
return dataStoreParam;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore.Parameters.Parameter in project hale by halestudio.
the class AppSchemaDataStoreConfigurationPage method updateConfiguration.
@Override
public boolean updateConfiguration(AbstractAppSchemaConfigurator provider) {
if (!validateHost()) {
updateMessage(Field.HOST);
return false;
}
if (!validateDatabase()) {
updateMessage(Field.DATABASE);
return false;
}
if (!validateSchema()) {
updateMessage(Field.SCHEMA);
return false;
}
DataStore dataStoreParam = provider.getParameter(AppSchemaIO.PARAM_DATASTORE).as(DataStore.class);
if (dataStoreParam == null) {
dataStoreParam = new DataStore();
}
if (dataStoreParam.getParameters() == null) {
dataStoreParam.setParameters(new Parameters());
}
String hostValue = host.getText();
Parameter hostParam = new Parameter();
hostParam.setName("host");
hostParam.setValue(extractHost(hostValue));
dataStoreParam.getParameters().getParameter().add(hostParam);
Integer portValue = extractPort(hostValue);
if (portValue != null) {
Parameter portParam = new Parameter();
portParam.setName("port");
portParam.setValue(portValue.toString());
dataStoreParam.getParameters().getParameter().add(portParam);
}
Parameter databaseParam = new Parameter();
databaseParam.setName("database");
databaseParam.setValue(database.getText());
dataStoreParam.getParameters().getParameter().add(databaseParam);
Parameter schemaParam = new Parameter();
schemaParam.setName("schema");
schemaParam.setValue(schema.getText());
dataStoreParam.getParameters().getParameter().add(schemaParam);
Parameter userParam = new Parameter();
userParam.setName("user");
userParam.setValue(user.getText());
dataStoreParam.getParameters().getParameter().add(userParam);
Parameter passwordParam = new Parameter();
passwordParam.setName("passwd");
passwordParam.setValue(password.getText());
dataStoreParam.getParameters().getParameter().add(passwordParam);
Parameter exposePKParam = new Parameter();
exposePKParam.setName("Expose primary keys");
exposePKParam.setValue(Boolean.toString(exposePK.getSelection()));
dataStoreParam.getParameters().getParameter().add(exposePKParam);
// TODO: only "postgis" dbtype is supported so far
dataStoreParam.getParameters().getParameter().add(DBTYPE_PARAMETER);
provider.setParameter(AppSchemaIO.PARAM_DATASTORE, new ComplexValue(dataStoreParam));
return true;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore.Parameters.Parameter in project hale by halestudio.
the class DataStoreComplexType method fromDOM.
/**
* @see eu.esdihumboldt.hale.common.core.io.ComplexValueType#fromDOM(org.w3c.dom.Element,
* java.lang.Object)
*/
@Override
public DataStore fromDOM(Element fragment, Void context) {
DataStore dataStore = new DataStore();
if (fragment != null) {
Element idEl = getFirstElementByTagName(fragment, "id", APP_SCHEMA_NAMESPACE);
if (idEl != null) {
dataStore.setId(idEl.getTextContent());
}
NodeList paramElements = fragment.getElementsByTagNameNS(APP_SCHEMA_NAMESPACE, "Parameter");
if (paramElements != null && paramElements.getLength() > 0) {
dataStore.setParameters(new Parameters());
for (int i = 0; i < paramElements.getLength(); i++) {
Element paramEl = (Element) paramElements.item(i);
Element paramNameEl = getFirstElementByTagName(paramEl, "name", APP_SCHEMA_NAMESPACE);
Element paramValueEl = getFirstElementByTagName(paramEl, "value", APP_SCHEMA_NAMESPACE);
if (paramNameEl != null && paramValueEl != null) {
Parameter param = new Parameter();
param.setName(paramNameEl.getTextContent());
param.setValue(paramValueEl.getTextContent());
dataStore.getParameters().getParameter().add(param);
}
}
}
}
return dataStore;
}
Aggregations