use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final Object bo = ctx.getTarget().getBusinessObject();
if (bo instanceof Feature) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the feature in the context of the EMV subclause. This is needed for reliable serialization.
final List<URI> path = ErrorModelGeUtil.createQualifiedPropagationPointPath(ctx.getTarget(), ErrorModelGeUtil.getClassifierSourceBoc(ctx.getTarget()).get(), new ArrayList<>());
newPropagation.setFeatureorPPRef(buildFeatureReference(subclause.eResource().getResourceSet(), path));
});
} else if (bo instanceof KeywordPropagationPoint) {
final KeywordPropagationPoint kw = (KeywordPropagationPoint) bo;
if (kw.getType() != KeywordPropagationPointType.ALL) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> newPropagation.setKind(kw.getType().getKind()));
}
} else if (bo instanceof PropagationPoint) {
return createPropgationCreationOperation(ctx.getTarget(), (newPropagation, subclause) -> {
// Find the propagation in the context of the EMV subclause.
// Check inherited subclauses as well. This is needed for reliable serialization.
final CombinedErrorModelSubclause combined = CombinedErrorModelSubclause.create(subclause.getContainingClassifier());
final String boName = ((PropagationPoint) bo).getName();
final PropagationPoint pp = combined.getPoints().filter(p -> Objects.equal(p.getName(), boName)).findAny().orElseThrow(() -> new AadlGraphicalEditorException("Unable to find propagation point"));
final FeatureorPPReference ppRef = ErrorModelFactory.eINSTANCE.createFeatureorPPReference();
ppRef.setFeatureorPP(pp);
newPropagation.setFeatureorPPRef(ppRef);
});
}
return Optional.empty();
}
use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.
the class CreateErrorPropagationPaletteCommand method createPropgationCreationOperation.
/**
* Creates an operation for creating a propagation for the target.
* @param target is the target of the propagation. It should be the context which will be the parent of the propagation
* @param init function called to finish initializing the propagation. It must set the kind or the feature or PP reference.
* @return the operation or an empty optional if a classifier could not be determined.
*/
private Optional<Operation> createPropgationCreationOperation(final BusinessObjectContext target, final BiConsumer<ErrorPropagation, ErrorModelSubclause> init) {
return ErrorModelGeUtil.getClassifierSourceBoc(target).flatMap(container -> {
final AadlPackage pkg = container.getBusinessObject(NamedElement.class).map(ne -> ne.getElementRoot()).map(root -> root instanceof AadlPackage ? ((AadlPackage) root) : null).orElseThrow(() -> new AadlGraphicalEditorException("Unable to find model"));
return ErrorModelGeUtil.createErrorModelSubclausePromptAndModifyOperation(container, () -> {
if (propagationAlreadyExists(target)) {
final String propagationOrContainmentLabel = (containment ? "containment" : "propagation");
final String inputOrOutputLabel = direction == DirectionType.IN ? "intput" : "output";
MessageDialog.openError(Display.getDefault().getActiveShell(), "Unable to create " + propagationOrContainmentLabel, "Propagation already exists. A propagation point may only have one " + inputOrOutputLabel + " error " + propagationOrContainmentLabel + " defined.");
return Optional.empty();
}
return ErrorModelUiUtil.promptForTypeSet(pkg);
}, (subclause, typeSet) -> {
final ErrorPropagation newPropagation = ErrorModelFactory.eINSTANCE.createErrorPropagation();
newPropagation.setTypeSet(typeSet);
newPropagation.setNot(containment);
newPropagation.setDirection(direction);
init.accept(newPropagation, subclause);
subclause.getPropagations().add(newPropagation);
return StepResultBuilder.create().showNewBusinessObject(target, newPropagation).build();
});
});
}
use of com.google.cloud.vision.v1p4beta1.Feature in project ddf by codice.
the class KmlMarshallerTest method unmarshall.
@Test
public void unmarshall() {
final InputStream resourceAsStream = this.getClass().getResourceAsStream("/kmlPoint.kml");
final Kml kml = kmlMarshaller.unmarshal(resourceAsStream).get();
final Feature feature = kml.getFeature();
assertThat(feature.getName(), is("Simple placemark"));
}
use of com.google.cloud.vision.v1p4beta1.Feature in project ddf by codice.
the class KmlMarshallerTest method unmarshallEmptyStream.
@Test(expected = NoSuchElementException.class)
public void unmarshallEmptyStream() {
final ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
final Kml kml = kmlMarshaller.unmarshal(inputStream).get();
final Feature feature = kml.getFeature();
assertThat(feature.getName(), is("Simple placemark"));
}
use of com.google.cloud.vision.v1p4beta1.Feature in project google-cloud-java by GoogleCloudPlatform.
the class VideoIntelligenceServiceClientTest method annotateVideoTest.
@Test
@SuppressWarnings("all")
public void annotateVideoTest() throws Exception {
AnnotateVideoResponse expectedResponse = AnnotateVideoResponse.newBuilder().build();
Operation resultOperation = Operation.newBuilder().setName("annotateVideoTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockVideoIntelligenceService.addResponse(resultOperation);
String inputUri = "inputUri1707300727";
List<Feature> features = new ArrayList<>();
VideoContext videoContext = VideoContext.newBuilder().build();
String outputUri = "outputUri-1273518802";
String locationId = "locationId552319461";
AnnotateVideoResponse actualResponse = client.annotateVideoAsync(inputUri, features, videoContext, outputUri, locationId).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockVideoIntelligenceService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnnotateVideoRequest actualRequest = (AnnotateVideoRequest) actualRequests.get(0);
Assert.assertEquals(inputUri, actualRequest.getInputUri());
Assert.assertEquals(features, actualRequest.getFeaturesList());
Assert.assertEquals(videoContext, actualRequest.getVideoContext());
Assert.assertEquals(outputUri, actualRequest.getOutputUri());
Assert.assertEquals(locationId, actualRequest.getLocationId());
}
Aggregations