org.alfresco.service.cmr.dictionary.DictionaryException Java Examples

The following examples show how to use org.alfresco.service.cmr.dictionary.DictionaryException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListOfValuesConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Set the values that are allowed by the constraint.
 *  
 * @param allowedValues a list of allowed values
 */
public void setAllowedValues(List<String> allowedValues)
{
    if (allowedValues == null)
    {
        throw new DictionaryException(ERR_NO_VALUES);
    }
    int valueCount = allowedValues.size();
    if (valueCount == 0)
    {
        throw new DictionaryException(ERR_NO_VALUES);
    }
    this.allowedValues = Collections.unmodifiableList(allowedValues);
    this.allowedValuesSet = new HashSet<String>(allowedValues);
    // make the upper case versions
    this.allowedValuesUpper = new ArrayList<String>(valueCount);
    this.allowedValuesUpperSet = new HashSet<String>(valueCount);
    for (String allowedValue : this.allowedValues)
    {
        String allowedValueUpper = allowedValue.toUpperCase();
        allowedValuesUpper.add(allowedValueUpper);
        allowedValuesUpperSet.add(allowedValueUpper);
    }
}
 
Example #2
Source File: AlfrescoSolrDataModel.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<String> validateModel(M2Model model)
{
    try
    {
        dictionaryDAO.getCompiledModel(QName.createQName(model.getName(), namespaceDAO));
    }
    catch (DictionaryException | NamespaceException exception)
    {
        // No model to diff
        return Collections.emptySet();
    }

    // namespace unknown - no model
    List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModelIgnoringConstraints(model);
    return modelDiffs.stream()
            .filter(diff -> diff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED))
            .map(diff ->
                    String.format("Model not updated: %s Failed to validate model update - found non-incrementally updated %s '%s'",
                            model.getName(),
                            diff.getElementType(),
                            diff.getElementName()))
            .collect(Collectors.toSet());
}
 
Example #3
Source File: TypeConverter.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * General conversion method to Object types (note it cannot support
 * conversion to primary types due the restrictions of reflection. Use the
 * static conversion methods to primitive types)
 * 
 * @param propertyType - the target property type
 * @param value - the value to be converted
 * @return - the converted value as the correct type
 */
public final Object convert(DataTypeDefinition propertyType, Object value)
{
    ParameterCheck.mandatory("Property type definition", propertyType);
    
    // Convert property type to java class
    Class<?> javaClass = null;
    String javaClassName = propertyType.getJavaClassName();
    try
    {
        javaClass = Class.forName(javaClassName);
    }
    catch (ClassNotFoundException e)
    {
        throw new DictionaryException("Java class " + javaClassName + " of property type " + propertyType.getName() + " is invalid", e);
    }
    
    return convert(javaClass, value);
}
 
Example #4
Source File: M2DataTypeDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
void resolveDependencies(ModelQuery query)
{
    // Ensure java class has been specified
    String javaClass = dataType.getJavaClassName();
    if (javaClass == null)
    {
        throw new DictionaryException(ERR_JAVA_CLASS_NOT_SPECIFIED, name.toPrefixString());
    }
    
    // Ensure java class is valid and referenceable
    try
    {
        Class.forName(javaClass);
    }
    catch (ClassNotFoundException e)
    {
        throw new DictionaryException(ERR_JAVA_CLASS_INVALID, javaClass, name.toPrefixString(), e);
    }
}
 
Example #5
Source File: M2ConstraintDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
synchronized void resolveDependencies(ModelQuery query, boolean enableConstraintClassLoading)
{
    if (resolving)
    {
        throw new DictionaryException(ERR_CYCLIC_REF, name.toPrefixString());
    }
    // prevent circular references
    try
    {
        resolving = true;
        resolveInternal(query, enableConstraintClassLoading);
    }
    finally
    {
        resolving = false;
    }
}
 
Example #6
Source File: TemporaryModels.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public QName loadModel(String modelPath, ClassLoader classLoader)
{
    InputStream modelStream = classLoader.getResourceAsStream(modelPath);
    if (modelStream == null)
    {
        throw new DictionaryException("Could not find bootstrap model " + modelPath);
    }
	try
	{
		return loadModel(modelStream); 
	}
    finally
    {
        try
        {
            modelStream.close();
        } 
        catch (IOException ioe)
        {
            logger.warn("Failed to close model input stream for '"+modelPath+"': "+ioe);
        }
    }
}
 
Example #7
Source File: DictionaryDAOImpl.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public TypeDefinition getAnonymousType(QName type, Collection<QName> aspects)
{
    TypeDefinition typeDef = getType(type);
    if (typeDef == null)
    {
        throw new DictionaryException(
                "d_dictionary.model.err.type_not_found", type);
    }
    Collection<AspectDefinition> aspectDefs = new ArrayList<AspectDefinition>();
    if (aspects != null)
    {
        for (QName aspect : aspects)
        {
            AspectDefinition aspectDef = getAspect(aspect);
            if (aspectDef == null)
            {
                throw new DictionaryException(
                        "d_dictionary.model.err.aspect_not_found", aspect);
            }
            aspectDefs.add(aspectDef);
        }
    }
    return new M2AnonymousTypeDefinition(typeDef, aspectDefs);
}
 
Example #8
Source File: TypeConverter.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * General conversion method to convert collection contents to the specified
 * type.
 * 
 * @param propertyType - the target property type
 * @param values - the value to be converted
 * @return - the converted value as the correct type
 * @throws DictionaryException if the property type's registered java class is invalid
 * @throws TypeConversionException if the conversion cannot be performed
 */
public final Collection<?> convert(DataTypeDefinition propertyType, Collection<?> values)
{
    ParameterCheck.mandatory("Property type definition", propertyType);
    
    // Convert property type to java class
    Class<?> javaClass = null;
    String javaClassName = propertyType.getJavaClassName();
    try
    {
        javaClass = Class.forName(javaClassName);
    }
    catch (ClassNotFoundException e)
    {
        throw new DictionaryException("Java class " + javaClassName + " of property type " + propertyType.getName() + " is invalid", e);
    }
    
    return convert(javaClass, values);
}
 
Example #9
Source File: M2Model.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void toXML(ModelDefinition.XMLBindingType bindingType, OutputStream xml)
{
    try
    {
    	if(bindingType == null)
    	{
    		bindingType = ModelDefinition.XMLBindingType.DEFAULT;
    	}

    	String bindingName = bindingType.toString();
        IBindingFactory factory = (bindingName != null) ? BindingDirectory.getFactory(bindingName, M2Model.class) :
        	BindingDirectory.getFactory("default", M2Model.class);
        IMarshallingContext context = factory.createMarshallingContext();
        context.setIndent(4);
        context.marshalDocument(this, "UTF-8", null, xml);
    }
    catch(JiBXException e)
    {
        throw new DictionaryException(ERR_CREATE_M2MODEL_FAILURE, e);
    }
}
 
Example #10
Source File: M2AssociationDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
void resolveDependencies(ModelQuery query)
{
    if (targetClassName == null)
    {
        throw new DictionaryException("d_dictionary.association.target_class_not_specified", name.toPrefixString());
    }
    targetClass = query.getClass(targetClassName);
    if (targetClass == null)
    {
        throw new DictionaryException("d_dictionary.association.target_class_not_found", targetClassName.toPrefixString(), name.toPrefixString());
    }
}
 
Example #11
Source File: QueryParserUtils.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static PropertyDefinition matchPropertyDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string)
{
    QName search = QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string));
    PropertyDefinition propertyDefinition = dictionaryService.getProperty(QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)));
    QName match = null;
    if (propertyDefinition == null)
    {
        for (QName definition : dictionaryService.getAllProperties(null))
        {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI()))
            {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName()))
                {
                    if (match == null)
                    {
                        match = definition;
                    }
                    else
                    {
                        throw new DictionaryException("Ambiguous data datype " + string);
                    }
                }
            }

        }
    }
    else
    {
        return propertyDefinition;
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return dictionaryService.getProperty(match);
    }
}
 
Example #12
Source File: M2DataTypeDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
M2DataTypeDefinition(ModelDefinition model, M2DataType propertyType, NamespacePrefixResolver resolver)
{
    this.model = model;
    this.name = QName.createQName(propertyType.getName(), resolver);
    if (!model.isNamespaceDefined(name.getNamespaceURI()))
    {
        throw new DictionaryException(ERR_NOT_DEFINED_NAMESPACE, name.toPrefixString(), name.getNamespaceURI(), model.getName().toPrefixString());
    }
    this.dataType = propertyType;
    this.analyserResourceBundleName = dataType.getAnalyserResourceBundleName();
}
 
Example #13
Source File: CompiledModel.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Construct
 * 
 * @param model model definition 
 * @param dictionaryDAO dictionary DAO
 * @param namespaceDAO namespace DAO
 */
/*package*/ CompiledModel(M2Model model, DictionaryDAO dictionaryDAO, NamespaceDAO namespaceDAO, boolean enableConstraintClassLoading)
{
    try
    {
        // Phase 1: Construct model definitions from model entries
        //          resolving qualified names
        this.model = model;
        constructDefinitions(model, namespaceDAO, dictionaryDAO);

        // Phase 2: Resolve dependencies between model definitions
        ModelQuery query = new DelegateModelQuery(this, dictionaryDAO);
        resolveDependencies(query, namespaceDAO);
        
        // Phase 3: Resolve inheritance of values within class hierachy
        NamespacePrefixResolver localPrefixes = createLocalPrefixResolver(model, namespaceDAO);
        resolveInheritance(query, localPrefixes, constraints);

        // Phase 4: Resolve constraint dependencies
        for (ConstraintDefinition def : constraints.values())
        {
            ((M2ConstraintDefinition)def).resolveDependencies(query, enableConstraintClassLoading);
        }
        
    }
    catch(Exception e)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Failed to compile model: " + model.getName(), e);
        }
        throw new DictionaryException(ERR_COMPILE_MODEL_FAILURE, e, model.getName());
    }
}
 
Example #14
Source File: AbstractDictionaryRegistry.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public CompiledModel getModel(QName modelName)
{
	CompiledModel model = getModelImpl(modelName);
       if(model == null)
       {
           throw new DictionaryException("d_dictionary.model.err.no_model", modelName);
       }
       return model;
}
 
Example #15
Source File: M2Model.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static M2Model createModel(String bindingName, InputStream xml)
{
    try
    {
        IBindingFactory factory = BindingDirectory.getFactory(bindingName, M2Model.class);
        IUnmarshallingContext context = factory.createUnmarshallingContext();
        Object obj = context.unmarshalDocument(xml, null);
        return (M2Model)obj;
    }
    catch(JiBXException e)
    {
        throw new DictionaryException(ERR_PARSE_FAILURE, e);
    }        
}
 
Example #16
Source File: M2ConstraintDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
M2ConstraintDefinition(ModelDefinition modelDefinition, M2PropertyDefinition m2PropertyDef,
        M2Constraint m2Constraint, NamespacePrefixResolver prefixResolver)
{
    this.model = modelDefinition;
    this.m2Constraint = m2Constraint;
    this.prefixResolver = prefixResolver;

    String constraintName = m2Constraint.getName();
    if (constraintName == null)
    {
        // the constraint is anonymous, so it has to be defined within the context of a property
        if (m2PropertyDef == null)
        {
            throw new DictionaryException(ERR_ANON_NEEDS_PROPERTY);
        }
        // pick the name up from the property and some anonymous value
        String localName = m2PropertyDef.getName().getLocalName() + "_anon_" + (++anonPropCount);
        this.name = QName.createQName(m2PropertyDef.getName().getNamespaceURI(), localName);
        m2Constraint.setName(this.name.getPrefixedQName(prefixResolver).toPrefixString());
    }
    else
    {
        this.name = QName.createQName(m2Constraint.getName(), prefixResolver);
        if (!model.isNamespaceDefined(name.getNamespaceURI()))
        {
            throw new DictionaryException(ERR_NAMESPACE_NOT_DEFINED, name.toPrefixString(), name.getNamespaceURI(), model.getName().toPrefixString());
        }
    }
}
 
Example #17
Source File: M2PropertyDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
void resolveDependencies(
        ModelQuery query,
        NamespacePrefixResolver prefixResolver,
        Map<QName, ConstraintDefinition> modelConstraints)
{
    if (propertyTypeName == null)
    {
        throw new DictionaryException(
                "d_dictionary.property.err.property_type_not_specified",
                name.toPrefixString());
    }
    dataType = query.getDataType(propertyTypeName);
    if (dataType == null)
    {
        throw new DictionaryException(
                "d_dictionary.property.err.property_type_not_found",
                propertyTypeName.toPrefixString(), name.toPrefixString());
    }
    
    // ensure content properties are not multi-valued
    if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued())
    {
        throw new DictionaryException("d_dictionary.property.err.single_valued_content");
    }

    // Construct constraints
    constraintDefs = buildConstraints(
            m2Property.getConstraints(),
            this,
            prefixResolver,
            modelConstraints);
}
 
Example #18
Source File: QueryParserUtils.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static AspectDefinition matchAspectDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string)
{
    QName search = QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string));
    AspectDefinition aspectDefinition = dictionaryService.getAspect(QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)));
    QName match = null;
    if (aspectDefinition == null)
    {
        for (QName definition : dictionaryService.getAllAspects())
        {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI()))
            {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName()))
                {
                    if (match == null)
                    {
                        match = definition;
                    }
                    else
                    {
                        throw new DictionaryException("Ambiguous data datype " + string);
                    }
                }
            }
        }
    }
    else
    {
        return aspectDefinition;
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return dictionaryService.getAspect(match);
    }
}
 
Example #19
Source File: QueryParserUtils.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static TypeDefinition matchTypeDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string) 
{
    QName search = QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string));
    TypeDefinition typeDefinition = dictionaryService.getType(QName.createQName(expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)));
    QName match = null;
    if (typeDefinition == null)
    {
        for (QName definition : dictionaryService.getAllTypes())
        {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI()))
            {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName()))
                {
                    if (match == null)
                    {
                        match = definition;
                    }
                    else
                    {
                        throw new DictionaryException("Ambiguous data datype " + string);
                    }
                }
            }
        }
    }
    else
    {
        return typeDefinition;
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return dictionaryService.getType(match);
    }
}
 
Example #20
Source File: QueryParserUtils.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static DataTypeDefinition matchDataTypeDefinition(String defaultNameSpaceUri, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String string) 
{
    QName search = QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string));
    DataTypeDefinition dataTypeDefinition = dictionaryService.getDataType(QName.createQName(QueryParserUtils.expandQName(defaultNameSpaceUri, namespacePrefixResolver, string)));
    QName match = null;
    if (dataTypeDefinition == null)
    {
        for (QName definition : dictionaryService.getAllDataTypes())
        {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI()))
            {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName()))
                {
                    if (match == null)
                    {
                        match = definition;
                    }
                    else
                    {
                        throw new DictionaryException("Ambiguous data datype " + string);
                    }
                }
            }

        }
    }
    else
    {
        return dataTypeDefinition;
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return dictionaryService.getDataType(match);
    }
}
 
Example #21
Source File: NumericRangeConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the maximum value allowed, which can be any value between
 * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE}.
 * 
 * @param maxValue the minimum value allowed by the constraint
 */
public void setMaxValue(double maxValue)
{
    if (maxValue < this.minValue)
    {
        throw new DictionaryException(ERR_INVALID_MAX_VALUE, maxValue);
    }
    this.maxValue = maxValue;
}
 
Example #22
Source File: NumericRangeConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the minimum value allowed, which can be any value between
 * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE}.
 * 
 * @param minValue the minimum value allowed by the constraint
 */
public void setMinValue(double minValue)
{
    if (minValue > this.maxValue)
    {
        throw new DictionaryException(ERR_INVALID_MIN_VALUE, minValue);
    }
    this.minValue = minValue;
}
 
Example #23
Source File: RegisteredConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return      the constraint that matches the registered name
 */
public Constraint getRegisteredConstraint()
{
    Constraint constraint = ConstraintRegistry.getInstance().getConstraint(registeredName);
    if (constraint == null)
    {
        throw new DictionaryException(ERR_NAME_NOT_REGISTERED, registeredName);
    }
    return constraint;
}
 
Example #24
Source File: RegisteredConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void initialize()
{
    if (registeredName == null)
    {
        throw new DictionaryException(AbstractConstraint.ERR_PROP_NOT_SET, "registeredName");
    }
}
 
Example #25
Source File: StringLengthConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the maximum number of characters allowed.  Valid values are in
 * the range [0, {@link Integer#MAX_VALUE}].
 * 
 * @param maxLength the minimum numbers of characters allowed
 */
public void setMaxLength(int maxLength)
{
    if (maxLength < this.minLength)
    {
        throw new DictionaryException(ERR_INVALID_MAX_LENGTH, maxLength);
    }
    this.maxLength = maxLength;
}
 
Example #26
Source File: StringLengthConstraint.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the minimum number of characters allowed.  Valid values are in
 * the range [0, {@link Integer#MAX_VALUE}].
 * 
 * @param minLength the minimum numbers of characters allowed
 */
public void setMinLength(int minLength)
{
    if (minLength > this.maxLength || minLength < 0)
    {
        throw new DictionaryException(ERR_INVALID_MIN_LENGTH, minLength);
    }
    this.minLength = minLength;
}
 
Example #27
Source File: DictionaryDAOImpl.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return diffs between input model and model in the Dictionary.
 * 
 * If the input model does not exist in the Dictionary then no diffs will be
 * returned.
 * 
 * @param model M2Model
 * @param enableConstraintClassLoading boolean
 * @return model diffs (if any)
 */
public List<M2ModelDiff> diffModel(M2Model model,
        boolean enableConstraintClassLoading)
{
    // Compile model definition
    CompiledModel compiledModel = model.compile(this, this,
            enableConstraintClassLoading);
    QName modelName = compiledModel.getModelDefinition().getName();

    CompiledModel previousVersion = null;
    try
    {
        previousVersion = getCompiledModel(modelName);
    }
    catch (DictionaryException e)
    {
         // ignore missing model, there's no need to warn about this.
        logger.debug(e);
    }

    if (previousVersion == null)
    {
        return new ArrayList<M2ModelDiff>(0);
    }
    else
    {
        return diffModel(previousVersion, compiledModel);
    }
}
 
Example #28
Source File: TemporaryModels.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public QName loadModel(InputStream modelStream) 
{
    try
    {
        final M2Model model = M2Model.createModel(modelStream);
        
        return loadModel(model);
    }
    catch(DictionaryException e)
    {
        throw new DictionaryException("Could not import model", e);
    }
	
}
 
Example #29
Source File: DictionaryDAOTest.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testBootstrapImportModelWithCircularTypes()
{
    TenantService tenantService = new SingleTServiceImpl();

    DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl();
    dictionaryDAO.setTenantService(tenantService);
    initDictionaryCaches(dictionaryDAO, tenantService);

    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();

    bootstrapModels.add("org/alfresco/repo/dictionary/modelCircularTypes.xml");
    bootstrap.setModels(bootstrapModels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);

    try
    {
        bootstrap.bootstrap();
        fail("Bootstrap should fail as the model contains a cyclic refrence");
    }
    catch(DictionaryException e)
    {
        assertEquals(e.getMsgId(), "d_dictionary.bootstrap.model_not_imported");
    }
}
 
Example #30
Source File: DictionaryDAOTest.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testCreateModelWithCircularTypeDependency()
{
    TenantService tenantService = new SingleTServiceImpl();

    DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl();
    dictionaryDAO.setTenantService(tenantService);
    initDictionaryCaches(dictionaryDAO, tenantService);

    //create model
    String testNamespace = "http://www.alfresco.org/model/dictionary/1.0/my";
    M2Model model = M2Model.createModel("my:circularModel");
    model.createNamespace(testNamespace, "my");
    model.setAnalyserResourceBundleName("typeModelResourceBundle");
    M2Type typeA = model.createType("my:circularA");
    typeA.setParentName("my:circularC");
    M2Type typeB = model.createType("my:circularB");
    typeB.setParentName("my:circularA");
    M2Type typeC = model.createType("my:circularC");
    typeC.setParentName("my:circularB");

    try
    {
        dictionaryDAO.putModel(model);
        fail("Model should not be saved successfully because it contains a cyclic reference");
    } catch(DictionaryException e)
    {
        assertEquals(e.getMsgId(), "d_dictionary.compiled_model.err.compile.failure");
    }
}