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

The following examples show how to use org.alfresco.service.cmr.dictionary.NamespaceDefinition. 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: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Validates models circular dependencies
 * <p>E.g. if {@literal B -> A} denotes  model B depends on model A, then {@link ConstraintViolatedException} must be thrown for following:
 * <li> if {@literal B -> A}, then {@literal A -> B} must throw exception </li>
 * <li> if {@literal B -> A} and {@literal C -> B}, then {@literal A -> C} must throw exception </li>
 * <li> if {@literal B -> A} and {@literal C -> B} and {@literal D -> C}, then {@literal A -> D} must throw exception </li>
 * @param modelDefinition the model which has a reference to the model containing the {@code parentPrefixedName}
 * @param existingModel the model being updated
 * @param parentPrefixedName the type/aspect parent name
 */
private void checkCircularDependency(ModelDefinition modelDefinition, CustomModel existingModel, String parentPrefixedName)
{
    for (NamespaceDefinition importedNamespace : modelDefinition.getImportedNamespaces())
    {
        ModelDefinition md = null;
        if ((md = customModelService.getCustomModelByUri(importedNamespace.getUri())) != null)
        {
            if (existingModel.getNamespaceUri().equals(importedNamespace.getUri()))
            {
                String msg = I18NUtil.getMessage("cmm.rest_api.circular_dependency_err", parentPrefixedName, existingModel.getName());
                throw new ConstraintViolatedException(msg);
            }
            checkCircularDependency(md, existingModel, parentPrefixedName);
        }
    }
}
 
Example #2
Source File: ModelValidatorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkCircularDependency(ModelDefinition model, M2Model existingModel, String parentPrefixedName) throws AlfrescoRuntimeException
{
    for (NamespaceDefinition importedNamespace : model.getImportedNamespaces())
    {
        ModelDefinition md = null;
        if ((md = dictionaryService.getModelByNamespaceUri(importedNamespace.getUri())) != null)
        {
            if (existingModel.getNamespace(importedNamespace.getUri()) != null)
            {
                throw new AlfrescoRuntimeException("Failed to validate model update - found circular dependency. You can't set parent " + parentPrefixedName + " as it's model already depends on " + existingModel.getName());
            }
            checkCircularDependency(md, existingModel, parentPrefixedName);
        }
    }
}
 
Example #3
Source File: DictionaryDAOImpl.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Collection<NamespaceDefinition> getNamespaces(QName modelName)
{
    CompiledModel model = getCompiledModel(modelName);
    ModelDefinition modelDef = model.getModelDefinition();
    return modelDef.getNamespaces();
}
 
Example #4
Source File: M2ModelDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Collection<NamespaceDefinition> getNamespaces()
{
    List<NamespaceDefinition> namespaces = new ArrayList<NamespaceDefinition>();
    for (M2Namespace namespace : model.getNamespaces())
    {
        namespaces.add(new M2NamespaceDefinition(this, namespace.getUri(), namespace.getPrefix()));
    }
    return namespaces;
}
 
Example #5
Source File: M2ModelDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Collection<NamespaceDefinition> getImportedNamespaces()
{
    List<NamespaceDefinition> namespaces = new ArrayList<NamespaceDefinition>();
    for (M2Namespace namespace : model.getImports())
    {
        namespaces.add(new M2NamespaceDefinition(this, namespace.getUri(), namespace.getPrefix()));
    }
    return namespaces;
}
 
Example #6
Source File: CustomModel.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CustomModel(CustomModelDefinition modelDefinition, List<CustomType> types, List<CustomAspect> aspects, List<CustomModelConstraint> constraints)
{
    this.name = modelDefinition.getName().getLocalName();
    this.author = modelDefinition.getAuthor();
    this.description = modelDefinition.getDescription();
    this.status = modelDefinition.isActive() ? ModelStatus.ACTIVE : ModelStatus.DRAFT;
    // we don't need to check for NoSuchElementException, as we don't allow
    // the model to be saved without a valid namespace
    NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
    this.namespaceUri = nsd.getUri();
    this.namespacePrefix = nsd.getPrefix();
    this.types = types;
    this.aspects = aspects;
    this.constraints = constraints;
}
 
Example #7
Source File: BaseCustomModelApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean hasNamespaceUri(Collection<NamespaceDefinition> namespaces, String expectedNamespaceUri)
{
    for (NamespaceDefinition ns : namespaces)
    {
        if (ns.getUri().equals(expectedNamespaceUri))
        {
            return true;
        }
    }

    return false;
}
 
Example #8
Source File: BaseCustomModelApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean hasNamespacePrefix(Collection<NamespaceDefinition> namespaces, String expectedNamespacePrefix)
{
    for (NamespaceDefinition ns : namespaces)
    {
        if (ns.getPrefix().equals(expectedNamespacePrefix))
        {
            return true;
        }
    }

    return false;
}
 
Example #9
Source File: M2ModelDiff.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public M2ModelDiff(QName elementName, NamespaceDefinition namespace, String elementType, String diffType)
{
    initModelDiff(elementName, elementType, diffType);
    this.namespace = namespace;
}
 
Example #10
Source File: M2ModelDiff.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public NamespaceDefinition getNamespaceDefinition()
{
   return namespace;
}
 
Example #11
Source File: CustomModelDefinitionImpl.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Collection<NamespaceDefinition> getImportedNamespaces()
{
    return m2ModelDefinition.getImportedNamespaces();
}
 
Example #12
Source File: CustomModelDefinitionImpl.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Collection<NamespaceDefinition> getNamespaces()
{
    return m2ModelDefinition.getNamespaces();
}
 
Example #13
Source File: CustomModelsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public CustomModel createCustomModel(M2Model m2Model)
{
    // Check the current user is authorised to import the custom model
    validateCurrentUser();

    validateImportedM2Model(m2Model);

    CompiledModel compiledModel = null;
    try
    {
        compiledModel = customModelService.compileModel(m2Model);
    }
    catch (CustomModelConstraintException mce)
    {
        throw new ConstraintViolatedException(mce.getMessage());
    }
    catch (InvalidCustomModelException iex)
    {
        throw new InvalidArgumentException(iex.getMessage());
    }

    ModelDefinition modelDefinition = compiledModel.getModelDefinition();
    CustomModel customModel = new CustomModel();
    customModel.setName(modelDefinition.getName().getLocalName());
    customModel.setAuthor(modelDefinition.getAuthor());
    customModel.setDescription(modelDefinition.getDescription(dictionaryService));
    customModel.setStatus(ModelStatus.DRAFT);
    NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
    customModel.setNamespaceUri(nsd.getUri());
    customModel.setNamespacePrefix(nsd.getPrefix());

    List<CustomType> customTypes = convertToCustomTypes(compiledModel.getTypes(), false);
    List<CustomAspect> customAspects = convertToCustomAspects(compiledModel.getAspects(), false);

    List<ConstraintDefinition> constraintDefinitions = CustomModelDefinitionImpl.removeInlineConstraints(compiledModel);
    List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);

    customModel.setTypes(customTypes);
    customModel.setAspects(customAspects);
    customModel.setConstraints(customModelConstraints);

    return createCustomModelImpl(customModel, false);
}
 
Example #14
Source File: DataDictionaryBuilderImpl.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
/**
 * @see java.lang.Object#toString()
 */
@Override
public String toString()
{
    final StringBuilder     result         = new StringBuilder(1024);
    final Collection<Model> dataDictionary = getDataDictionary();
    
    result.append("Models:");
    
    if (dataDictionary != null)
    {
        for (Model model : dataDictionary)
        {
            ModelDefinition modelDefinition = model.model;
            
            result.append("\n\t");
            result.append(modelDefinition.getName().toPrefixString());
            
            result.append("\n\t\tNamespaces:");
            Collection<NamespaceDefinition> namespaces = modelDefinition.getNamespaces();
            if (namespaces != null && namespaces.size() > 0)
            {
                for (NamespaceDefinition namespace : namespaces)
                {
                    result.append("\n\t\t\t");
                    result.append(namespace.getPrefix());
                    result.append(" = ");
                    result.append(namespace.getUri());
                }
            }
            else
            {
                result.append("\n\t\t\t<none>");
            }
            
            result.append("\n\t\tConstraints:");
            if (model.constraints != null && model.constraints.size() > 0)
            {
                for (ConstraintDefinition constraint : model.constraints)
                {
                    result.append("\n\t\t\t");
                    result.append(constraint.getName().toPrefixString());
                }
            }
            else
            {
                result.append("\n\t\t\t<none>");
            }
            
            result.append("\n\t\tTypes:");
            if (model.types != null && model.types.size() > 0)
            {
                for (TypeDefinition type : model.types)
                {
                    result.append(classDefinitionToString(type));
                }
            }
            else
            {
                result.append("\n\t\t\t<none>");
            }

            result.append("\n\t\tAspects:");
            if (model.aspects != null && model.aspects.size() > 0)
            {
                for (AspectDefinition aspect : model.aspects)
                {
                    result.append(classDefinitionToString(aspect));
                }
            }
            else
            {
                result.append("\n\t\t\t<none>");
            }
        }
    }
    else
    {
        result.append("\n\t<none>");
    }
    
    return(result.toString());
}
 
Example #15
Source File: DictionaryDAO.java    From alfresco-data-model with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * @param modelName
 *            the model to retrieve namespaces for
 * @return the namespaces of the model
 */
Collection<NamespaceDefinition> getNamespaces(QName modelName);