@Test public void testMetaDataUpdateName() throws Exception { ModelerWorkspace model = new ModelerWorkspace(new ModelerWorkspaceHelper("")); model.setDomain(new XmiParser().parseXmi(new FileInputStream(PRODUCT_XMI_FILE))); model.getWorkspaceHelper().populateDomain(model); // Initial measure exists LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); OlapCube cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); List<OlapMeasure> olapMeasures = cube.getOlapMeasures(); assertNotNull(AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures)); // Renaming the measure UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_FORMULA); updateMeasure.setName(NEW_BUYPRICE_NAME); boolean isApplied = updateMeasure.apply(model, metaStore); assertTrue(isApplied); // Make sure the initial measure name cannot be found and the new measure name exists logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); olapMeasures = cube.getOlapMeasures(); assertNull(AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures)); assertNotNull(AnnotationUtil.getOlapMeasure(NEW_BUYPRICE_NAME, olapMeasures)); }
@Test public void testMetaDataUpdateFormat() throws Exception { ModelerWorkspace model = new ModelerWorkspace(new ModelerWorkspaceHelper("")); model.setDomain(new XmiParser().parseXmi(new FileInputStream(PRODUCT_XMI_FILE))); model.getWorkspaceHelper().populateDomain(model); // Initial measure exists LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); OlapCube cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); List<OlapMeasure> olapMeasures = cube.getOlapMeasures(); OlapMeasure measure = AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures); assertNotNull(measure); assertNull(measure.getLogicalColumn().getProperty("mask")); // Changing the aggregation type UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_FORMULA); updateMeasure.setName(INIT_BUYPRICE_NAME); updateMeasure.setFormat(NEW_FORMAT); boolean isApplied = updateMeasure.apply(model, metaStore); assertTrue(isApplied); // Ensure the aggregation type got set logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); olapMeasures = cube.getOlapMeasures(); measure = AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures); assertNotNull(measure); assertEquals(NEW_FORMAT, measure.getLogicalColumn().getProperty("mask")); }
@Test public void testMetaDataNoDuplicateNames() throws Exception { ModelerWorkspace model = new ModelerWorkspace(new ModelerWorkspaceHelper("")); model.setDomain(new XmiParser().parseXmi(new FileInputStream(PRODUCT_XMI_FILE))); model.getWorkspaceHelper().populateDomain(model); // Initial measure exists LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); OlapCube cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); List<OlapMeasure> olapMeasures = cube.getOlapMeasures(); assertNotNull(AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures)); // Renaming the measure UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_FORMULA); updateMeasure.setName(EXISTING_NAME); boolean isApplied = updateMeasure.apply(model, metaStore); assertFalse(isApplied); // Make sure nothing has changed logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); cube = ((List<OlapCube>) logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_CUBES)).get(0); olapMeasures = cube.getOlapMeasures(); OlapMeasure oldMeasure = AnnotationUtil.getOlapMeasure(INIT_BUYPRICE_NAME, olapMeasures); assertNotNull(oldMeasure); INIT_BUYPRICE_COLUMN.equals(oldMeasure.getLogicalColumn().getName()); oldMeasure = AnnotationUtil.getOlapMeasure(EXISTING_NAME, olapMeasures); assertNotNull(oldMeasure); EXISTING_COLUMN.equals(oldMeasure.getLogicalColumn().getName()); }
private void buildMetaValues( AnyKeyCollection any, MetaBeanBuilder metaBeanBuilder, ControllerBuilder controllerBuilder, ComponentRegistry componentRegistry) throws InstantiationException, IllegalAccessException { if (any.metaValuesDefinition() == MetaValuesDefinition.class) { if (any.metaValues().length == 0) throw new MappingException("meta values is required"); for (MetaValue value : any.metaValues()) { super.applyInternalConfiguration( new ImportBeanEntry(value.target()), controllerBuilder, componentRegistry); metaBeanBuilder.addMetaValue(value.name(), AnnotationUtil.getBeanName(value.target())); } } else { Class<? extends MetaValuesDefinition> metaClassDefinition = any.metaValuesDefinition(); MetaValuesDefinition metaValuesDefinition = (MetaValuesDefinition) ClassUtil.getInstance(metaClassDefinition); List<MetaValueDefinition> list = metaValuesDefinition.getMetaValues(); if (list == null || list.isEmpty()) throw new MappingException("meta values cannot be empty"); for (MetaValueDefinition value : list) { super.applyInternalConfiguration( new ImportBeanEntry(value.getTarget()), controllerBuilder, componentRegistry); metaBeanBuilder.addMetaValue( value.getName(), AnnotationUtil.getBeanName(value.getTarget())); } } }
public Object applyConfiguration0( Object source, Object builder, ComponentRegistry componentRegistry) throws InstantiationException, IllegalAccessException { KeyEntry keyEntry = (KeyEntry) source; KeyBuilder keyBuilder = (KeyBuilder) builder; AnyKeyCollection anyKeyCollection = keyEntry.getAnnotation(AnyKeyCollection.class); Basic basic = anyKeyCollection.metaBean(); Class<?> metaType = anyKeyCollection.metaType(); String key = StringUtil.isEmpty(basic.bean()) ? keyEntry.getName() : basic.bean(); EnumerationType enumType = keyEntry.getEnumerated(); String tempType = keyEntry.getTemporal(); ScopeType scope = AnnotationUtil.getScope(basic); org.brandao.brutos.type.Type type = keyEntry.getType() == null ? null : AnnotationUtil.getTypeInstance(keyEntry.getType()); MetaBeanBuilder metaBeanBuilder = keyBuilder.buildMetaBean(key, scope, enumType, tempType, metaType, type); this.buildMetaValues( anyKeyCollection, metaBeanBuilder, keyBuilder.getBeanBuilder().getControllerBuilder(), componentRegistry); super.applyInternalConfiguration(key, keyBuilder, componentRegistry); return builder; }
@Nullable private PsiAnnotation findNullabilityAnnotation( @NotNull PsiModifierListOwner owner, boolean checkBases, boolean nullable) { Set<String> qNames = ContainerUtil.newHashSet(nullable ? getNullables() : getNotNulls()); PsiAnnotation annotation = checkBases && (owner instanceof PsiClass || owner instanceof PsiMethod) ? AnnotationUtil.findAnnotationInHierarchy(owner, qNames) : AnnotationUtil.findAnnotation(owner, qNames); if (annotation != null) { return annotation; } if (owner instanceof PsiParameter && !TypeConversionUtil.isPrimitiveAndNotNull(((PsiParameter) owner).getType())) { // even if javax.annotation.Nullable is not configured, it should still take precedence over // ByDefault annotations if (AnnotationUtil.isAnnotated( owner, nullable ? Arrays.asList(DEFAULT_NOT_NULLS) : Arrays.asList(DEFAULT_NULLABLES), checkBases, false)) { return null; } return findContainerAnnotation( owner, nullable ? "javax.annotation.ParametersAreNullableByDefault" : "javax.annotation.ParametersAreNonnullByDefault"); } return null; }
@Test public void testMondrianUpdateFormat() throws Exception { File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH); Document mondrianSchemaXmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile); assertTrue(mondrianSchemaXmlDoc != null); // Check existing state assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, INIT_BUYPRICE_COLUMN, AnnotationUtil.NAME_ATTRIB, INIT_BUYPRICE_COLUMN)); assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, INIT_BUYPRICE_COLUMN, AnnotationUtil.FORMATSTRING_ATTRIB, INIT_FORMAT)); // Changing the aggregation type UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA); updateMeasure.setName(INIT_BUYPRICE_COLUMN); updateMeasure.setFormat(NEW_FORMAT); boolean isApplied = updateMeasure.apply(mondrianSchemaXmlDoc); assertTrue(isApplied); // Check change assertTrue( mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength() > 0); assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, INIT_BUYPRICE_COLUMN, AnnotationUtil.NAME_ATTRIB, INIT_BUYPRICE_COLUMN)); assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, INIT_BUYPRICE_COLUMN, AnnotationUtil.FORMATSTRING_ATTRIB, NEW_FORMAT)); }
@Test public void testUpdatesCaptionNameUnchanged() throws Exception { File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH); Document mondrianSchemaXmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile); // Renaming the measure UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA); updateMeasure.setCaption(NEW_BUYPRICE_NAME); boolean isApplied = updateMeasure.apply(mondrianSchemaXmlDoc); assertTrue(isApplied); assertTrue(mondrianSchemaXmlDoc != null); assertTrue( mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength() > 0); assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, INIT_BUYPRICE_COLUMN, AnnotationUtil.CAPTION_ATTRIB, NEW_BUYPRICE_NAME)); }
@Test public void testMondrianNoDuplicateNames() throws Exception { File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH); Document mondrianSchemaXmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile); // Renaming the measure UpdateMeasure updateMeasure = new UpdateMeasure(); updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA); updateMeasure.setName(EXISTING_COLUMN); assertFalse(updateMeasure.apply(mondrianSchemaXmlDoc)); // Ensure nothing has changed assertTrue(mondrianSchemaXmlDoc != null); assertTrue( mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength() > 0); // Ensure new Element was not created assertFalse( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, NEW_BUYPRICE_NAME, AnnotationUtil.NAME_ATTRIB, "")); // Ensure original element still exists assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc, AnnotationUtil.MEASURE_ELEMENT_NAME, EXISTING_COLUMN, AnnotationUtil.NAME_ATTRIB, EXISTING_COLUMN)); }
@Nullable private static PsiAnnotation findContainerAnnotation( PsiModifierListOwner owner, String annotationFQN) { PsiElement element = owner.getParent(); while (element != null) { if (element instanceof PsiModifierListOwner) { PsiAnnotation annotation = AnnotationUtil.findAnnotation((PsiModifierListOwner) element, annotationFQN); if (annotation != null) { return annotation; } } if (element instanceof PsiClassOwner) { String packageName = ((PsiClassOwner) element).getPackageName(); PsiPackage psiPackage = JavaPsiFacade.getInstance(element.getProject()).findPackage(packageName); return AnnotationUtil.findAnnotation(psiPackage, annotationFQN); } element = element.getContext(); } return null; }