use of com.google.pubsub.v1.Schema in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method d_siteTrTest.
@Ignore(value = "Geoserver is Down")
@Test
public void d_siteTrTest() throws Exception {
String wfsURL = "http://150.145.141.241/geoserver/wfs";
QName siteTRCom = new QName("cite:tr_com");
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(siteTRCom));
Schema response = request.getResponse();
String localPart = siteTRCom.getLocalPart();
String name = localPart.substring(localPart.indexOf(":") + 1);
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
logger.debug("######################RESPONSE_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.info("###################################FEATURE_COLLECTION : {}\n", featureCollection);
getFeatureRequest.setGeometryName(layerSchema.getGeometry().getName());
getFeatureRequest.setBBox(new BBox(10.329274141729897, 44.64877730606194, 10.35673996203874, 44.66831396911103));
logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
logger.debug("######################RESPONSE_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
InputStream si = getFeatureRequest.getResponseAsStream();
FeatureCollectionDTO featureCollectionByBBOX = featureReaderStAX.read(si);
if (!featureCollectionByBBOX.isFeaturesLoaded()) {
featureCollectionByBBOX.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.info("###################################FEATURE_COLLECTION_BY_BBOX : {}\n", featureCollectionByBBOX);
}
use of com.google.pubsub.v1.Schema in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method b_statesTest.
// @Ignore(value = "FIX PROBLEM TO RETRIEVE ATTRIBUTES WITHOUT GEOMETRY")
@Test
public void b_statesTest() throws Exception {
String wfsURL = "http://150.145.141.92/geoserver/wfs";
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(states));
Schema response = request.getResponse();
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, statesName);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setPropertyNames(asList(new String[] { "STATE_NAME", "PERSONS" }));
getFeatureRequest.setBBox(new BBox(-75.102613, 40.212597, -72.361859, 41.512517));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("\n\t@@@@@@@@@@@@@@@@@@RESPONSE_AS_STRING : {}", getFeatureRequest.getResponseAsString());
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.debug("\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@FEATURE_COLLECTION_DTO : {}", featureCollection.getNumberOfFeatures());
}
use of com.google.pubsub.v1.Schema in project odata-client by davidmoten.
the class GeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException {
if (schemas == null) {
schemas = Collections.emptyList();
}
List<SchemaOptions> schemaOptionsList = schemas.stream().map(s -> new SchemaOptions(s.namespace, s.packageName, s.packageSuffixEnum, s.packageSuffixEntity, s.packageSuffixComplexType, s.packageSuffixEntityRequest, s.packageSuffixCollectionRequest, s.packageSuffixContainer, s.packageSuffixSchema, s.simpleClassNameSchema, s.collectionRequestClassSuffix, s.entityRequestClassSuffix, //
s.actionRequestClassSuffix, //
s.pageComplexTypes, s.failOnMissingEntitySet)).collect(Collectors.toList());
InputStream is = null;
try {
InputStream cis = GeneratorMojo.class.getResourceAsStream(metadata);
if (cis == null) {
File metadataFile = new File(metadata);
System.out.println("metadataFile = " + metadataFile.getAbsolutePath());
if (metadataFile.exists()) {
is = new FileInputStream(metadataFile);
} else {
metadataFile = new File(project.getBasedir(), metadata);
System.out.println("metadataFile = " + metadataFile.getAbsolutePath());
if (metadataFile.exists()) {
is = new FileInputStream(metadataFile);
} else {
throw new MojoExecutionException("could not find metadata on classpath or file system: " + metadata);
}
}
} else {
is = cis;
}
JAXBContext c = JAXBContext.newInstance(TDataServices.class);
Unmarshaller unmarshaller = c.createUnmarshaller();
TEdmx t = unmarshaller.unmarshal(new StreamSource(is), TEdmx.class).getValue();
// log schemas
List<Schema> schemas = t.getDataServices().getSchema();
schemas.forEach(sch -> getLog().info("schema: " + sch.getNamespace()));
// auto generate options when not configured
List<SchemaOptions> schemaOptionsList2 = //
schemas.stream().flatMap(schema -> {
Optional<SchemaOptions> o = //
schemaOptionsList.stream().filter(//
so -> schema.getNamespace().equals(so.namespace)).findFirst();
if (o.isPresent()) {
return Stream.of(o.get());
} else if (!autoPackage) {
return Stream.empty();
} else {
getLog().info("schema options not found so autogenerating for namespace=" + schema.getNamespace());
return Stream.of(new SchemaOptions(schema.getNamespace(), blankIfNull(autoPackagePrefix) + toPackage(schema.getNamespace())));
}
}).collect(Collectors.toList());
Options options = new Options(outputDirectory.getAbsolutePath(), schemaOptionsList2);
Generator g = new Generator(options, schemas);
g.generate();
} catch (Throwable e) {
if (e instanceof MojoExecutionException) {
throw (MojoExecutionException) e;
} else {
throw new MojoExecutionException(e.getMessage(), e);
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
}
use of com.google.pubsub.v1.Schema in project odata-client by davidmoten.
the class Generator method writeEntityCollectionRequest.
private void writeEntityCollectionRequest(Schema schema, TEntityType entityType, Map<String, List<Action>> collectionTypeActions, Map<String, List<Function>> collectionTypeFunctions, Set<String> collectionTypes) {
EntityType t = new EntityType(entityType, names);
if (!collectionTypes.contains(t.getFullType())) {
return;
}
names.getDirectoryEntityCollectionRequest(schema).mkdirs();
String simpleClassName = names.getSimpleClassNameCollectionRequest(schema, t.getName());
Imports imports = new Imports(names.getFullClassNameCollectionRequest(schema, t.getName()));
Indent indent = new Indent();
StringWriter w = new StringWriter();
try (PrintWriter p = new PrintWriter(w)) {
p.format("package %s;\n\n", names.getPackageCollectionRequest(schema));
p.format(IMPORTSHERE);
p.format("public class %s extends %s<%s, %s>{\n\n", simpleClassName, imports.add(CollectionPageEntityRequest.class), //
imports.add(names.getFullClassNameFromTypeWithoutNamespace(schema, t.getName())), imports.add(names.getFullClassNameEntityRequest(schema, t.getName())));
indent.right();
addContextPathField(imports, indent, p);
// add constructor
//
p.format(//
"\n%spublic %s(%s contextPath, %s<%s> value) {\n", //
indent, //
simpleClassName, //
imports.add(ContextPath.class), //
imports.add(Optional.class), imports.add(Object.class));
//
p.format(//
"%ssuper(contextPath, %s.class, cp -> new %s(cp, Optional.empty()), value);\n", //
indent.right(), //
imports.add(names.getFullClassNameFromTypeWithoutNamespace(schema, t.getName())), imports.add(names.getFullClassNameEntityRequestFromTypeWithoutNamespace(schema, t.getName())));
p.format("%sthis.contextPath = contextPath;\n", indent);
p.format("%s}\n", indent.left());
// write fields from properties
//
t.getNavigationProperties().forEach(x -> {
Schema sch = names.getSchema(names.getInnerType(names.getType(x)));
if (x.getType().get(0).startsWith(COLLECTION_PREFIX)) {
String y = names.getInnerType(names.getType(x));
if (names.isEntityWithNamespace(y)) {
String entityRequestType = names.getFullClassNameEntityRequestFromTypeWithNamespace(sch, y);
EntityType et = names.getEntityType(y);
KeyInfo k = getKeyInfo(et, imports);
if (!k.isEmpty()) {
p.format("\n%spublic %s %s(%s) {\n", indent, imports.add(entityRequestType), Names.getIdentifier(x.getName()), k.typedParams);
p.format("%sreturn new %s(contextPath.addSegment(\"%s\")%s, %s.empty());\n", indent.right(), imports.add(entityRequestType), x.getName(), k.addKeys, imports.add(Optional.class));
p.format("%s}\n", indent.left());
}
}
//
p.format(//
"\n%spublic %s %s() {\n", //
indent, imports.add(//
names.getFullClassNameCollectionRequestFromTypeWithNamespace(sch, y)), Names.getIdentifier(x.getName()));
//
p.format(//
"%sreturn new %s(contextPath.addSegment(\"%s\"), %s.empty());\n", //
indent.right(), imports.add(//
names.getFullClassNameCollectionRequestFromTypeWithNamespace(sch, y)), //
x.getName(), imports.add(Optional.class));
p.format("%s}\n", indent.left());
}
});
Set<String> methodNames = new HashSet<>();
writeBoundActionMethods(t, collectionTypeActions, imports, indent, p, methodNames);
writeBoundFunctionMethods(t, collectionTypeFunctions, imports, indent, p, methodNames);
indent.left();
p.format("\n}\n");
writeToFile(imports, w, t.getClassFileCollectionRequest());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.google.pubsub.v1.Schema in project odata-client by davidmoten.
the class Generator method writeSchemaInfo.
private void writeSchemaInfo(Schema schema) {
names.getDirectorySchema(schema).mkdirs();
String simpleClassName = names.getSimpleClassNameSchema(schema);
Imports imports = new Imports(names.getFullClassNameSchema(schema));
Indent indent = new Indent();
try {
StringWriter w = new StringWriter();
try (PrintWriter p = new PrintWriter(w)) {
p.format("package %s;\n\n", names.getPackageSchema(schema));
p.format(IMPORTSHERE);
p.format("public enum %s implements %s {\n\n", simpleClassName, imports.add(SchemaInfo.class));
// add enum
p.format("%sINSTANCE;\n\n", indent.right());
// add fields for entities map
//
p.format(//
"%sprivate final %s<%s, %s<? extends %s>> classes = new %s<>();\n\n", //
indent, //
imports.add(Map.class), //
imports.add(String.class), //
imports.add(Class.class), //
imports.add(ODataType.class), imports.add(HashMap.class));
// add private constructor
p.format("%sprivate %s() {\n", indent, simpleClassName);
indent.right();
// write all schemas classes into map not just the current one
// TODO use one SchemasInfo.class
//
names.getSchemas().stream().flatMap(//
sch -> Util.filter(sch.getComplexTypeOrEntityTypeOrTypeDefinition(), TEntityType.class)).forEach(x -> {
Schema sch = names.getSchema(x);
p.format("%sclasses.put(\"%s\", %s.class);\n", indent, names.getFullTypeFromSimpleType(sch, x.getName()), imports.add(names.getFullClassNameEntity(sch, x.getName())));
});
//
names.getSchemas().stream().flatMap(sch -> Util.filter(sch.getComplexTypeOrEntityTypeOrTypeDefinition(), //
TComplexType.class)).forEach(x -> {
Schema sch = names.getSchema(x);
p.format("%sclasses.put(\"%s\", %s.class);\n", indent, names.getFullTypeFromSimpleType(sch, x.getName()), imports.add(names.getFullClassNameComplexType(sch, x.getName())));
});
indent.left();
p.format("%s}\n\n", indent);
// add method
p.format("%s@%s\n", indent, imports.add(Override.class));
//
p.format(//
"%spublic %s<? extends %s> getClassFromTypeWithNamespace(%s name) {\n", //
indent, //
imports.add(Class.class), //
imports.add(ODataType.class), imports.add(String.class));
p.format("%sreturn classes.get(name);\n", indent.right());
p.format("%s}\n\n", indent.left());
// close class
p.format("}\n");
}
byte[] bytes = w.toString().replace(IMPORTSHERE, imports.toString()).getBytes(StandardCharsets.UTF_8);
Files.write(names.getClassFileSchema(schema).toPath(), bytes);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations