private void addAnnotations(final DataObject dataObject, final List<AnnotationMetaModel> annotationMetaModelList) { for (AnnotationMetaModel annotationMetaModel : annotationMetaModelList) { final String name = annotationMetaModel.name; final Map<String, String> values = annotationMetaModel.values; Annotation annotation; String key = DroolsDomainAnnotations.VALUE_PARAM; String value = ""; if (values.size() > 0) { key = values.keySet().iterator().next(); value = values.values().iterator().next(); } if ("Role".equals(name)) { annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.ROLE_ANNOTATION)); annotation.setValue(key, value); dataObject.addAnnotation(annotation); } else if ("Position".equals(name)) { annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.POSITION_ANNOTATION)); annotation.setValue(key, value); dataObject.addAnnotation(annotation); } else if ("Equals".equals(name)) { annotation = new AnnotationImpl(annotationDefinitions.get(DroolsDomainAnnotations.KEY_ANNOTATION)); annotation.setValue(key, value); dataObject.addAnnotation(annotation); } } }
@Override public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException { org.kie.soup.project.datamodel.oracle.Annotation oracleAnnotationToken = (org.kie.soup.project.datamodel.oracle.Annotation)annotationToken; AnnotationImpl annotation = new AnnotationImpl(annotationDefinition); if (annotationDefinition.isMarker()) { return annotation; } else if (oracleAnnotationToken.getParameters() != null) { Object currentAttributeValue; for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) { currentAttributeValue = oracleAnnotationToken.getParameters().get(annotationMember.getName()); if (currentAttributeValue != null) { annotation.setValue(annotationMember.getName(), currentAttributeValue); } } } return annotation; } }
public Annotation createAnnotation( Map<String, AnnotationDefinition> systemAnnotations, String className, String memberName, Object value ) { AnnotationDefinition annotationDefinition = systemAnnotations.get( className ); Annotation annotation = new AnnotationImpl( annotationDefinition ); if ( memberName != null ) { annotation.setValue( memberName, value ); } return annotation; } }
@Override public Annotation buildAnnotation( AnnotationDefinition annotationDefinition, Object annotationToken ) throws ModelDriverException { AnnotationSource javaAnnotationToken = ( AnnotationSource ) annotationToken; AnnotationImpl annotation = new AnnotationImpl( annotationDefinition ); if ( annotationDefinition.isMarker() ) { return annotation; } else { if ( javaAnnotationToken.getValues() != null ) { List<ValuePair> values = javaAnnotationToken.getValues(); if ( values != null && values.size() > 0 ) { for ( AnnotationValuePairDefinition valuePairDefinition : annotationDefinition.getValuePairs() ) { Object annotationValue = buildAnnotationValue( javaAnnotationToken, valuePairDefinition ); if ( annotationValue != null ) { annotation.setValue( valuePairDefinition.getName(), annotationValue ); } } } } } return annotation; }
dataObject.addAnnotation( new AnnotationImpl( modelDriver.getConfiguredAnnotation( Entity.class.getName() ) ) ); Annotation tableAnnotation = new AnnotationImpl( modelDriver.getConfiguredAnnotation( Table.class.getName() ) ); tableAnnotation.setValue( "name", tableName.trim() ); dataObject.addAnnotation( tableAnnotation ); id.addAnnotation( new AnnotationImpl( modelDriver.getConfiguredAnnotation( Id.class.getName() ) ) ); Annotation generatedValue = new AnnotationImpl( modelDriver.getConfiguredAnnotation( GeneratedValue.class.getName() ) ); generatedValue.setValue( "generator", generatorName ); generatedValue.setValue( "strategy", GenerationType.AUTO.name() ); Annotation sequenceGenerator = new AnnotationImpl( modelDriver.getConfiguredAnnotation( SequenceGenerator.class.getName() ) ); Boolean.valueOf( portableParams.get( "audited" ).toString() ) : false; if ( isAuditable ) { Annotation audited = new AnnotationImpl( modelDriver.getConfiguredAnnotation( Audited.class.getName() ) ); audited.setValue( "targetAuditMode", RelationTargetAuditMode.NOT_AUDITED.name() ); dataObject.addAnnotation( audited );
AnnotationImpl annotation = new AnnotationImpl(annotationDefinition); if (annotationDefinition.isMarker()) { return annotation; for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) { if ("value".equals(annotationMember.getName())) { annotation.setValue( annotationMember.getName(), parseParamValue(annotationDefinition, annotationMember.getName(), javaAnnotationToken.getElementValue().getValue() )); ElementValueDescr value = valuePairValues.get( annotationMember.getName() ); if (value != null) { annotation.setValue(annotationMember.getName(), parseParamValue( annotationDefinition, annotationMember.getName(), value.getValue()) );
public static Annotation createAnnotation(Class cls, String memberName, Object value) { AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(cls); Annotation annotation = new AnnotationImpl(annotationDefinition); if (memberName != null) { annotation.setValue(memberName, value); } return annotation; }
@Before public void init() { eventObserver = createObserver(); descriptorModel = createModel(); dataObject = new DataObjectImpl("package1", "PersistableObject"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class))); when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH); when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath); when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); }
@Test public void checkPlanningSolutionNoOtherExists() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Arrays.asList(dataObjectPath)); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertTrue(result.isEmpty()); }
@Test public void checkPlanningSolutionNoOtherExistsFirstSave() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Collections.emptyList()); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertTrue(result.isEmpty()); }
@Test public void postProcess() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); Package _package = mock(Package.class); when(_package.getPackageMainResourcesPath()).thenReturn(PathFactory.newPath("dataObjects", "file:///dataObjects")); when(kieModuleService.resolvePackage(sourcePath)).thenReturn(_package); when(ioService.exists(any())).thenReturn(true); copyHelper.postProcess(sourcePath, destinationPath); verify(ioService, times(1)).copy(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class)); }
private DataObject createDataObject(Class<? extends Score> scoreClass) { DataObject dataObject = new DataObjectImpl("test", "Test"); if (scoreClass != null) { dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); dataObject.addProperty("score", scoreClass.getName()); } return dataObject; } }
@Test public void postProcess() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); Package _package = mock(Package.class); when(_package.getPackageMainResourcesPath()).thenReturn(PathFactory.newPath("dataObjects", "file:///dataObjects")); when(kieModuleService.resolvePackage(sourcePath)).thenReturn(_package); when(ioService.exists(any())).thenReturn(true); deleteHelper.postProcess(sourcePath); verify(ioService, times(1)).deleteIfExists(any(org.uberfire.java.nio.file.Path.class)); }
@Test public void checkPlanningSolutionOtherExists() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); Path otherDataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Arrays.asList(otherDataObjectPath)); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertEquals(1, result.size()); ValidationMessage message = result.iterator().next(); assertTrue(message instanceof PlanningSolutionToBeDuplicatedMessage); } }
@Test public void postProcess() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); Package _package = mock(Package.class); when(_package.getPackageMainResourcesPath()).thenReturn(PathFactory.newPath("dataObjects", "file:///dataObjects")); when(kieModuleService.resolvePackage(sourcePath)).thenReturn(_package); when(ioService.exists(any())).thenReturn(true); renameHelper.postProcess(sourcePath, destinationPath); verify(ioService, times(1)).move(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class)); }
@Test public void pathValidation_dataObjectIsPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningSolutionToBeDuplicatedMessage); } }
@Test public void validateIsAPlanningScore() { DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); ObjectProperty objectProperty = new ObjectPropertyImpl("score", HardSoftScore.class.getName(), false); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class))); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Generated.class))); Collection<ValidationMessage> result = deleteValidator.validate(dataObject, objectProperty); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningScoreToBeDeletedMessage); }
@Test public void checkDataObjectIsAPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath, dataObject); assertEquals(1, result.size()); ValidationMessage message = result.iterator().next(); assertTrue(message instanceof PlanningSolutionToBeDuplicatedMessage); }
@Test public void pathValidation_noMessagesWhenGenerationFails() { GenerationResult generationResult = new GenerationResult(); generationResult.setErrors(Collections.singletonList(new DataModelerError())); DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(0, result.size()); }
dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(dataObject);