-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from apache/SP-1065
Sp 1065
- Loading branch information
Showing
25 changed files
with
672 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...he/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.streampipes.extensions.management.connect.adapter.format.geojson; | ||
|
||
public class GeoJsonConstants { | ||
public static final String LATITUDE = "latitude"; | ||
public static final String LONGITUDE = "longitude"; | ||
public static final String ALTITUDE = "altitude"; | ||
|
||
public static final String COORDINATES = "coordinates"; | ||
public static final String COORDINATES_LINE_STRING = "coordinatesLineString"; | ||
public static final String COORDINATES_POLYGON = "coordinatesPolygon"; | ||
public static final String COORDINATES_MULTI_POINT = "coordinatesMultiPoint"; | ||
public static final String COORDINATES_MULTI_STRING = "coordinatesMultiString"; | ||
public static final String COORDINATES_MULTI_POLYGON = "coordinatesMultiPolygon"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...che/streampipes/extensions/management/connect/adapter/format/json/AbstractJsonParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.apache.streampipes.extensions.management.connect.adapter.format.json; | ||
|
||
import org.apache.streampipes.commons.exceptions.SpRuntimeException; | ||
import org.apache.streampipes.dataformat.json.JsonDataFormatDefinition; | ||
import org.apache.streampipes.extensions.api.connect.exception.ParseException; | ||
import org.apache.streampipes.extensions.management.connect.adapter.format.util.JsonEventProperty; | ||
import org.apache.streampipes.extensions.management.connect.adapter.model.generic.Parser; | ||
import org.apache.streampipes.model.connect.guess.AdapterGuessInfo; | ||
import org.apache.streampipes.model.connect.guess.GuessTypeInfo; | ||
import org.apache.streampipes.model.schema.EventProperty; | ||
import org.apache.streampipes.model.schema.EventSchema; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class AbstractJsonParser extends Parser { | ||
|
||
@Override | ||
public EventSchema getEventSchema(List<byte[]> oneEvent) { | ||
return getSchemaAndSample(oneEvent).getEventSchema(); | ||
} | ||
|
||
@Override | ||
public boolean supportsPreview() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public AdapterGuessInfo getSchemaAndSample(List<byte[]> eventSample) throws ParseException { | ||
EventSchema resultSchema = new EventSchema(); | ||
|
||
JsonDataFormatDefinition jsonDefinition = new JsonDataFormatDefinition(); | ||
|
||
|
||
Map<String, Object> exampleEvent; | ||
|
||
try { | ||
exampleEvent = jsonDefinition.toMap(eventSample.get(0)); | ||
var sample = exampleEvent | ||
.entrySet() | ||
.stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, e -> | ||
new GuessTypeInfo(e.getValue().getClass().getCanonicalName(), e.getValue()))); | ||
|
||
for (Map.Entry<String, Object> entry : exampleEvent.entrySet()) { | ||
EventProperty p = JsonEventProperty.getEventProperty(entry.getKey(), entry.getValue()); | ||
|
||
resultSchema.addEventProperty(p); | ||
} | ||
|
||
return new AdapterGuessInfo(resultSchema, sample); | ||
} catch (SpRuntimeException e) { | ||
throw new ParseException("Could not serialize event, did you choose the correct format?", e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.