AbstractKogitoDMNService implements KogitoDMNService { protected Map<String, ClientDMNType> getDMNDataTypesMap(final List<JSITItemDefinition> jsitItemDefinitions, final String nameSpace) { Map<String, ClientDMNType> dmnDataTypesMap = new HashMap<>(); for (BuiltInType type : BuiltInType.values()) { for (String name : type.getNames()) { ClientDMNType feelPrimitiveType; if (type == BuiltInType.CONTEXT) { feelPrimitiveType = new ClientDMNType(URI_FEEL, name, null, false, true, Collections.emptyMap(), type); } else { feelPrimitiveType = new ClientDMNType(URI_FEEL, name, null, false, type); } dmnDataTypesMap.put(name, feelPrimitiveType); } } final Map<String, JSITItemDefinition> itemDefinitionMap = indexDefinitionsByName(jsitItemDefinitions); for (int i = 0; i < jsitItemDefinitions.size(); i++) { final JSITItemDefinition jsitItemDefinition = Js.uncheckedCast(jsitItemDefinitions.get(i)); getOrCreateDMNType(itemDefinitionMap, jsitItemDefinition.getName(), nameSpace, dmnDataTypesMap); } return Collections.unmodifiableMap(dmnDataTypesMap); }  @Override FactModelTuple getFactModelTuple(final JSITDefinitions jsitDefinitions); boolean isJSITInputData(JSITDRGElement jsitdrgElement); boolean isJSITDecision(JSITDRGElement jsitdrgElement); Map<QName, String> getOtherAttributesMap(JSITDMNElement jsitInputDataVariable); static final String URI_FEEL; static final String WRONG_DMN_MESSAGE; }
@Test public void getDMNTypesMapEmptyItemDefinitions() { Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(jstiItemDefinitions, NAMESPACE); assertTrue(dmnTypesMap.size() == 14); for (Map.Entry<String, ClientDMNType> entry : dmnTypesMap.entrySet()) { assertNotNull(entry.getValue().getFeelType()); assertTrue(Arrays.stream(entry.getValue().getFeelType().getNames()).anyMatch(entry.getKey()::equals)); } for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void getDMNTypesMapWithItemDefinitions() { jstiItemDefinitions.add(jsitItemDefinitionMock); Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(jstiItemDefinitions, NAMESPACE); assertTrue(dmnTypesMap.size() == 15); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } assertNotNull(dmnTypesMap.get(TYPE_NAME)); assertNull(dmnTypesMap.get(TYPE_NAME).getFeelType()); assertEquals(TYPE_NAME, dmnTypesMap.get(TYPE_NAME).getName()); assertEquals(NAMESPACE, dmnTypesMap.get(TYPE_NAME).getNamespace()); assertFalse(dmnTypesMap.get(TYPE_NAME).isCollection()); }
@Test public void testGetCustomWithItemComponentDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String addressFieldName = "address"; final String countryFieldName = "country"; when(tPeople.getName()).thenReturn(tPeopleType); final JSITItemDefinition address = mock(JSITItemDefinition.class); when(address.getName()).thenReturn(addressFieldName); final List<JSITItemDefinition> tPeopleFields = Arrays.asList(address); final JSITItemDefinition country = mock(JSITItemDefinition.class); when(country.getName()).thenReturn(countryFieldName); when(country.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); final List<JSITItemDefinition> tAddressFields = Arrays.asList(country); when(tPeople.getItemComponent()).thenReturn(tPeopleFields); when(address.getItemComponent()).thenReturn(tAddressFields); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); assertEquals(1, dmnPeopleType.getFields().size()); assertTrue(dmnPeopleType.getFields().containsKey(addressFieldName)); assertNull(dmnPeopleType.getFeelType()); assertFalse(dmnPeopleType.isCollection()); assertTrue(dmnPeopleType.isComposite()); ClientDMNType addressType = dmnPeopleType.getFields().get(addressFieldName); assertNotNull(addressType); assertEquals(1, addressType.getFields().size()); assertTrue(addressType.getFields().containsKey(countryFieldName)); assertNull(addressType.getFeelType()); assertFalse(addressType.isCollection()); assertTrue(addressType.isComposite()); ClientDMNType countryType = addressType.getFields().get(countryFieldName); assertEquals(0, countryType.getFields().size()); assertEquals(BuiltInType.STRING, countryType.getFeelType()); assertFalse(countryType.isCollection()); assertFalse(countryType.isComposite()); assertTrue(dmnTypesMap.size() == 15); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetCustomInheritsSimpleCustomDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tMen = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tMenType = "tMenType"; when(tMen.getName()).thenReturn(tMenType); when(tMen.getTypeRef()).thenReturn(tPeopleType); when(tPeople.getName()).thenReturn(tPeopleType); when(tPeople.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tMen); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); assertTrue(dmnPeopleType.getFields().isEmpty()); assertEquals(BuiltInType.STRING, dmnPeopleType.getFeelType()); assertFalse(dmnPeopleType.isCollection()); assertFalse(dmnPeopleType.isComposite()); final ClientDMNType dmnMenType = dmnTypesMap.get(tMenType); assertTrue(dmnMenType.getFields().isEmpty()); assertEquals((BuiltInType.STRING), dmnMenType.getFeelType()); assertFalse(dmnMenType.isCollection()); assertFalse(dmnMenType.isComposite()); assertTrue(dmnTypesMap.size() == 16); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetCustomCollectionInheritsSimpleCustomDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tMen = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tMenType = "tMenType"; when(tMen.getName()).thenReturn(tMenType); when(tMen.getTypeRef()).thenReturn(tPeopleType); when(tMen.getIsCollection()).thenReturn(true); when(tPeople.getName()).thenReturn(tPeopleType); when(tPeople.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tMen); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); assertTrue(dmnPeopleType.getFields().isEmpty()); assertEquals(BuiltInType.STRING, dmnPeopleType.getFeelType()); assertFalse(dmnPeopleType.isCollection()); assertFalse(dmnPeopleType.isComposite()); final ClientDMNType dmnMenType = dmnTypesMap.get(tMenType); assertTrue(dmnMenType.getFields().isEmpty()); assertEquals(BuiltInType.STRING, dmnMenType.getFeelType()); assertTrue(dmnMenType.isCollection()); assertFalse(dmnMenType.isComposite()); assertTrue(dmnTypesMap.size() == 16); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetCustomInheritsSimpleCustomCollectionDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tMen = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tMenType = "tMenType"; when(tMen.getName()).thenReturn(tMenType); when(tMen.getTypeRef()).thenReturn(tPeopleType); when(tPeople.getName()).thenReturn(tPeopleType); when(tPeople.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); when(tPeople.getIsCollection()).thenReturn(true); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tMen); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); assertTrue(dmnPeopleType.getFields().isEmpty()); assertEquals(BuiltInType.STRING, dmnPeopleType.getFeelType()); assertTrue(dmnPeopleType.isCollection()); assertFalse(dmnPeopleType.isComposite()); final ClientDMNType dmnMenType = dmnTypesMap.get(tMenType); assertTrue(dmnMenType.getFields().isEmpty()); assertEquals(BuiltInType.STRING, dmnMenType.getFeelType()); assertTrue(dmnMenType.isCollection()); assertFalse(dmnMenType.isComposite()); assertTrue(dmnTypesMap.size() == 16); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetRecursiveDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tAddress = mock(JSITItemDefinition.class); final JSITItemDefinition tCountry = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tAddressType = "tAddressType"; final String tCountryType = "tCountryType"; final String addressFieldName = "address"; final String countryFieldName = "president"; final String peopleFieldName = "people"; when(tPeople.getName()).thenReturn(tPeopleType); when(tAddress.getName()).thenReturn(tAddressType); when(tCountry.getName()).thenReturn(tCountryType); final JSITItemDefinition address = mock(JSITItemDefinition.class); when(address.getTypeRef()).thenReturn(tAddressType); when(address.getName()).thenReturn(addressFieldName); final List<JSITItemDefinition> tPeopleFields = Arrays.asList(address); final JSITItemDefinition country = mock(JSITItemDefinition.class); when(country.getName()).thenReturn(countryFieldName); when(country.getTypeRef()).thenReturn(tCountryType); final List<JSITItemDefinition> tAddressFields = Arrays.asList(country); final JSITItemDefinition people = mock(JSITItemDefinition.class); when(people.getTypeRef()).thenReturn(tPeopleType); when(people.getName()).thenReturn(peopleFieldName); final List<JSITItemDefinition> tCountryFields = Arrays.asList(people); when(tPeople.getItemComponent()).thenReturn(tPeopleFields); when(tAddress.getItemComponent()).thenReturn(tAddressFields); when(tCountry.getItemComponent()).thenReturn(tCountryFields); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tAddress, tCountry); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); assertTrue(dmnTypesMap.containsKey(tAddressType)); assertTrue(dmnTypesMap.containsKey(tCountryType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); final ClientDMNType dmnAddressType = dmnTypesMap.get(tAddressType); final ClientDMNType dmnCountryType = dmnTypesMap.get(tCountryType); assertEquals(1, dmnPeopleType.getFields().size()); assertTrue(dmnPeopleType.getFields().containsKey(addressFieldName)); assertEquals(dmnAddressType, dmnPeopleType.getFields().get(addressFieldName)); assertFalse(dmnPeopleType.isCollection()); assertTrue(dmnPeopleType.isComposite()); assertEquals(1, dmnAddressType.getFields().size()); assertTrue(dmnAddressType.getFields().containsKey(countryFieldName)); assertEquals(dmnCountryType, dmnAddressType.getFields().get(countryFieldName)); assertFalse(dmnAddressType.isCollection()); assertTrue(dmnAddressType.isComposite()); assertEquals(1, dmnCountryType.getFields().size()); assertTrue(dmnCountryType.getFields().containsKey(peopleFieldName)); assertEquals(dmnPeopleType, dmnCountryType.getFields().get(peopleFieldName)); assertFalse(dmnCountryType.isCollection()); assertTrue(dmnCountryType.isComposite()); assertTrue(dmnTypesMap.size() == 17); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetRecursiveAndDataTypeCollectionDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tAddress = mock(JSITItemDefinition.class); final JSITItemDefinition tCountry = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tAddressType = "tAddressType"; final String tCountryType = "tCountryType"; final String addressFieldName = "address"; final String countryFieldName = "president"; final String peopleFieldName = "people"; when(tPeople.getName()).thenReturn(tPeopleType); when(tAddress.getName()).thenReturn(tAddressType); when(tCountry.getName()).thenReturn(tCountryType); when(tPeople.getIsCollection()).thenReturn(true); final JSITItemDefinition address = mock(JSITItemDefinition.class); when(address.getTypeRef()).thenReturn(tAddressType); when(address.getName()).thenReturn(addressFieldName); final List<JSITItemDefinition> tPeopleFields = Arrays.asList(address); final JSITItemDefinition country = mock(JSITItemDefinition.class); when(country.getName()).thenReturn(countryFieldName); when(country.getTypeRef()).thenReturn(tCountryType); final List<JSITItemDefinition> tAddressFields = Arrays.asList(country); final JSITItemDefinition people = mock(JSITItemDefinition.class); when(people.getTypeRef()).thenReturn(tPeopleType); when(people.getName()).thenReturn(peopleFieldName); final List<JSITItemDefinition> tCountryFields = Arrays.asList(people); when(tPeople.getItemComponent()).thenReturn(tPeopleFields); when(tAddress.getItemComponent()).thenReturn(tAddressFields); when(tCountry.getItemComponent()).thenReturn(tCountryFields); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tAddress, tCountry); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); assertTrue(dmnTypesMap.containsKey(tAddressType)); assertTrue(dmnTypesMap.containsKey(tCountryType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); final ClientDMNType dmnAddressType = dmnTypesMap.get(tAddressType); final ClientDMNType dmnCountryType = dmnTypesMap.get(tCountryType); assertEquals(1, dmnPeopleType.getFields().size()); assertTrue(dmnPeopleType.getFields().containsKey(addressFieldName)); assertEquals(dmnAddressType, dmnPeopleType.getFields().get(addressFieldName)); assertTrue(dmnPeopleType.isCollection()); assertTrue(dmnPeopleType.isComposite()); assertEquals(1, dmnAddressType.getFields().size()); assertTrue(dmnAddressType.getFields().containsKey(countryFieldName)); assertEquals(dmnCountryType, dmnAddressType.getFields().get(countryFieldName)); assertFalse(dmnAddressType.isCollection()); assertTrue(dmnAddressType.isComposite()); assertEquals(1, dmnCountryType.getFields().size()); assertTrue(dmnCountryType.getFields().containsKey(peopleFieldName)); assertEquals(dmnPeopleType, dmnCountryType.getFields().get(peopleFieldName)); assertFalse(dmnCountryType.isCollection()); assertTrue(dmnCountryType.isComposite()); assertTrue(dmnTypesMap.size() == 17); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }
@Test public void testGetRecursiveAndFieldCollectionsDMNTypes() { final JSITItemDefinition tPeople = mock(JSITItemDefinition.class); final JSITItemDefinition tAddress = mock(JSITItemDefinition.class); final JSITItemDefinition tCountry = mock(JSITItemDefinition.class); final String tPeopleType = "tPeopleType"; final String tAddressType = "tAddressType"; final String tCountryType = "tCountryType"; final String addressFieldName = "address"; final String countryFieldName = "president"; final String peopleFieldName = "people"; final String regionsName = "regions"; final String nameLabel = "name"; when(tPeople.getName()).thenReturn(tPeopleType); when(tAddress.getName()).thenReturn(tAddressType); when(tCountry.getName()).thenReturn(tCountryType); final JSITItemDefinition address = mock(JSITItemDefinition.class); when(address.getTypeRef()).thenReturn(tAddressType); when(address.getName()).thenReturn(addressFieldName); final List<JSITItemDefinition> tPeopleFields = Arrays.asList(address); final JSITItemDefinition country = mock(JSITItemDefinition.class); when(country.getName()).thenReturn(countryFieldName); when(country.getTypeRef()).thenReturn(tCountryType); final List<JSITItemDefinition> tAddressFields = Arrays.asList(country); final JSITItemDefinition people = mock(JSITItemDefinition.class); when(people.getTypeRef()).thenReturn(tPeopleType); when(people.getName()).thenReturn(peopleFieldName); when(people.getIsCollection()).thenReturn(true); final JSITItemDefinition regions = mock(JSITItemDefinition.class); when(regions.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); when(regions.getName()).thenReturn(regionsName); when(regions.getIsCollection()).thenReturn(true); final JSITItemDefinition nameField = mock(JSITItemDefinition.class); when(nameField.getTypeRef()).thenReturn(BuiltInType.STRING.getName()); when(nameField.getName()).thenReturn(nameLabel); final List<JSITItemDefinition> tCountryFields = Arrays.asList(people, regions, nameField); when(tPeople.getItemComponent()).thenReturn(tPeopleFields); when(tAddress.getItemComponent()).thenReturn(tAddressFields); when(tCountry.getItemComponent()).thenReturn(tCountryFields); final List<JSITItemDefinition> definitions = Arrays.asList(tPeople, tAddress, tCountry); final Map<String, ClientDMNType> dmnTypesMap = abstractKogitoDMNServiceSpy.getDMNDataTypesMap(definitions, "namespace"); assertTrue(dmnTypesMap.containsKey(tPeopleType)); assertTrue(dmnTypesMap.containsKey(tAddressType)); assertTrue(dmnTypesMap.containsKey(tCountryType)); final ClientDMNType dmnPeopleType = dmnTypesMap.get(tPeopleType); final ClientDMNType dmnAddressType = dmnTypesMap.get(tAddressType); final ClientDMNType dmnCountryType = dmnTypesMap.get(tCountryType); final ClientDMNType stringType = dmnTypesMap.get(BuiltInType.STRING.getName()); assertEquals(1, dmnPeopleType.getFields().size()); assertTrue(dmnPeopleType.getFields().containsKey(addressFieldName)); assertEquals(dmnAddressType, dmnPeopleType.getFields().get(addressFieldName)); assertNull(dmnPeopleType.getFeelType()); assertFalse(dmnPeopleType.isCollection()); assertTrue(dmnPeopleType.isComposite()); assertEquals(1, dmnAddressType.getFields().size()); assertTrue(dmnAddressType.getFields().containsKey(countryFieldName)); assertEquals(dmnCountryType, dmnAddressType.getFields().get(countryFieldName)); assertNull(dmnAddressType.getFeelType()); assertFalse(dmnAddressType.isCollection()); assertTrue(dmnAddressType.isComposite()); assertEquals(3, dmnCountryType.getFields().size()); assertTrue(dmnCountryType.getFields().containsKey(peopleFieldName)); assertNotEquals(dmnPeopleType, dmnCountryType.getFields().get(peopleFieldName)); assertTrue(dmnCountryType.getFields().get(peopleFieldName).isCollection()); assertTrue(dmnCountryType.getFields().get(peopleFieldName).isComposite()); assertEquals(tPeopleType, dmnCountryType.getFields().get(peopleFieldName).getName()); assertTrue(dmnCountryType.getFields().containsKey(regionsName)); assertNull(dmnCountryType.getFeelType()); assertNotEquals(stringType, dmnCountryType.getFields().get(regionsName)); assertTrue(dmnCountryType.getFields().get(regionsName).isCollection()); assertFalse(dmnCountryType.getFields().get(regionsName).isComposite()); assertEquals(BuiltInType.STRING.getName(), dmnCountryType.getFields().get(regionsName).getName()); assertTrue(dmnCountryType.getFields().containsKey(nameLabel)); assertEquals(stringType, dmnCountryType.getFields().get(nameLabel)); assertEquals(BuiltInType.STRING, stringType.getFeelType()); assertFalse(stringType.isCollection()); assertFalse(stringType.isComposite()); assertTrue(dmnTypesMap.size() == 17); for (BuiltInType builtInType : BuiltInType.values()) { Arrays.stream(builtInType.getNames()).forEach(name -> assertNotNull(dmnTypesMap.get(name))); } }