org.alfresco.service.cmr.dictionary.ModelDefinition Java Examples
The following examples show how to use
org.alfresco.service.cmr.dictionary.ModelDefinition.
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: M2Label.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
/** * Get label for data dictionary item given specified locale * * @param locale Locale * @param model ModelDefinition * @param messageLookup MessageLookup * @param type String * @param item QName * @param label String * @return String */ public static String getLabel(Locale locale, ModelDefinition model, MessageLookup messageLookup, String type, QName item, String label) { if (messageLookup == null) { return null; } String key = model.getName().toPrefixString(); if (type != null) { key += "." + type; } if (item != null) { key += "." + item.toPrefixString(); } key += "." + label; key = StringUtils.replace(key, ":", "_"); return messageLookup.getMessage(key, locale); }
Example #2
Source File: M2Model.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 6 votes |
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 #3
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 #4
Source File: AlfrescoModelGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private void handle(WebScriptRequest req, WebScriptResponse res) throws JSONException, IOException { // create map of template vars String modelQName = req.getParameter("modelQName"); if(modelQName == null) { throw new WebScriptException( Status.STATUS_BAD_REQUEST, "URL parameter 'modelQName' not provided."); } ModelDefinition.XMLBindingType bindingType = ModelDefinition.XMLBindingType.DEFAULT; AlfrescoModel model = solrTrackingComponent.getModel(QName.createQName(modelQName)); res.setHeader("XAlfresco-modelChecksum", String.valueOf(model.getModelDef().getChecksum(bindingType))); model.getModelDef().toXML(bindingType, res.getOutputStream()); }
Example #5
Source File: RepoDictionaryDAOTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testLabels() { QName model = QName.createQName(TEST_URL, "dictionarydaotest"); ModelDefinition modelDef = service.getModel(model); assertEquals("Model Description", modelDef.getDescription(service)); QName type = QName.createQName(TEST_URL, "base"); TypeDefinition typeDef = service.getType(type); assertEquals("Base Title", typeDef.getTitle(service)); assertEquals("Base Description", typeDef.getDescription(service)); QName prop = QName.createQName(TEST_URL, "prop1"); PropertyDefinition propDef = service.getProperty(prop); assertEquals("Prop1 Title", propDef.getTitle(service)); assertEquals("Prop1 Description", propDef.getDescription(service)); QName assoc = QName.createQName(TEST_URL, "assoc1"); AssociationDefinition assocDef = service.getAssociation(assoc); assertEquals("Assoc1 Title", assocDef.getTitle(service)); assertEquals("Assoc1 Description", assocDef.getDescription(service)); QName datatype = QName.createQName(TEST_URL, "datatype"); DataTypeDefinition datatypeDef = service.getDataType(datatype); assertEquals("alfresco/model/dataTypeAnalyzers", datatypeDef.getAnalyserResourceBundleName()); }
Example #6
Source File: ModelValidatorImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
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 #7
Source File: M2DataTypeDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
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 #8
Source File: M2Model.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
public long getChecksum(ModelDefinition.XMLBindingType bindingType) { final CRC32 crc = new CRC32(); // construct the crc directly from the model's xml stream toXML(bindingType, new OutputStream() { public void write(int b) throws IOException { crc.update(b); } }); return crc.getValue(); }
Example #9
Source File: DictionaryComponent.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ModelDefinition getModelByNamespaceUri(String uri) { for(QName modelQname : dictionaryDAO.getModels()) { if(modelQname.getNamespaceURI().equals(uri)) { return getModel(modelQname); } } return null; }
Example #10
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
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 #11
Source File: DictionaryDAOImpl.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Collection<NamespaceDefinition> getNamespaces(QName modelName) { CompiledModel model = getCompiledModel(modelName); ModelDefinition modelDef = model.getModelDefinition(); return modelDef.getNamespaces(); }
Example #12
Source File: AlfrescoSolrDataModel.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the Alfresco models associated with the current dictionary. * * @return the Alfresco models associated with the current dictionary. */ public List<AlfrescoModel> getAlfrescoModels() { return dictionaryDAO.getModels().stream() .map(qname -> { M2Model m2Model = dictionaryDAO.getCompiledModel(qname).getM2Model(); return new AlfrescoModel( m2Model, getDictionaryService( CMISStrictDictionaryService.DEFAULT).getModel(qname).getChecksum(ModelDefinition.XMLBindingType.DEFAULT));}) .collect(Collectors.toList()); }
Example #13
Source File: CustomModelServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testisNamespaceUriExists() { final String modelName = makeUniqueName("testCustomModel"); final Pair<String, String> namespacePair = getTestNamespacePrefixPair(); M2Model model = M2Model.createModel(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + modelName); model.createNamespace(namespacePair.getFirst(), namespacePair.getSecond()); model.setAuthor("John Doe"); assertNull(customModelService.getCustomModelByUri(namespacePair.getFirst())); // Create the model CustomModelDefinition modelDefinition = createModel(model, false); assertNotNull(modelDefinition); assertEquals(modelName, modelDefinition.getName().getLocalName()); ModelDefinition modelDefinitionByUri = transactionHelper.doInTransaction(new RetryingTransactionCallback<ModelDefinition>() { @Override public ModelDefinition execute() throws Throwable { assertTrue(customModelService.isNamespaceUriExists(namespacePair.getFirst())); return customModelService.getCustomModelByUri(namespacePair.getFirst()); } }); assertNotNull(modelDefinitionByUri); assertEquals(modelName, modelDefinitionByUri.getName().getLocalName()); }
Example #14
Source File: SOLRTrackingComponentImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ public AlfrescoModel getModel(QName modelName) { if(enabled) { ModelDefinition modelDef = dictionaryService.getModel(modelName); return (modelDef != null ? new AlfrescoModel(modelDef) : null); } else { return null; } }
Example #15
Source File: RepoModelDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
RepoModelDefinition(String repoName, String repoVersion, ModelDefinition model, boolean loaded) { this.repoName = repoName; this.repoVersion = repoVersion; this.model = model; this.loaded = loaded; }
Example #16
Source File: CustomModelServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ModelDefinition getCustomModelByUri(String namespaceUri) { ParameterCheck.mandatoryString("namespaceUri", namespaceUri); CompiledModel compiledModel = getModelByUri(namespaceUri); if (compiledModel != null) { return compiledModel.getModelDefinition(); } return null; }
Example #17
Source File: M2PropertyDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModel() { return classDef.getModel(); }
Example #18
Source File: M2ConstraintDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ModelDefinition getModel() { return model; }
Example #19
Source File: CustomModelsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@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 #20
Source File: AdminWebScriptTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModel() { return null; }
Example #21
Source File: ModelValidatorImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void validateModel(CompiledModel compiledModel) { ModelDefinition modelDef = compiledModel.getModelDefinition(); QName modelName = modelDef.getName(); M2Model model = compiledModel.getM2Model(); checkCustomModelNamespace(model, TenantUtil.getCurrentDomain()); List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(model); for (M2ModelDiff modelDiff : modelDiffs) { if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_DELETED)) { // TODO - check tenants if model is shared / inherited if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_PROPERTY)) { validateDeleteProperty(modelName, modelDiff.getElementName(), false); } else if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_CONSTRAINT)) { validateDeleteConstraint(compiledModel, modelDiff.getElementName(), false); } else { /* * As the M2Model#compile method will detect and throw exception for any missing namespace which * is required to define any Type, Aspect or Property, we can safely add this extra check. * See APPSREPO-59 comment for details. */ if (!modelDiff.getElementType().equals(M2ModelDiff.TYPE_NAMESPACE)) { throw new AlfrescoRuntimeException("Failed to validate model update - found deleted " + modelDiff.getElementType() + " '" + modelDiff .getElementName() + "'"); } } } if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED)) { throw new AlfrescoRuntimeException("Failed to validate model update - found non-incrementally updated " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'"); } if(modelDiff.getDiffType().equals(M2ModelDiff.DIFF_CREATED)) { if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_NAMESPACE)) { ModelDefinition importedModel = dictionaryService.getModelByNamespaceUri(modelDiff.getNamespaceDefinition().getUri()); if(importedModel != null && !model.getNamespaces().isEmpty()) { checkCircularDependency(importedModel, model, importedModel.getName().getLocalName()); } } } } // TODO validate that any deleted constraints are not being referenced - else currently will become anon - or push down into model compilation (check backwards compatibility ...) }
Example #22
Source File: M2AnonymousTypeDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModel() { return type.getModel(); }
Example #23
Source File: DataDictionaryBuilderImpl.java From alfresco-bulk-import with Apache License 2.0 | 4 votes |
/** * @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 #24
Source File: M2TypeDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
M2TypeDefinition(ModelDefinition model, M2Type m2Type, NamespacePrefixResolver resolver, Map<QName, PropertyDefinition> modelProperties, Map<QName, AssociationDefinition> modelAssociations) { super(model, m2Type, resolver, modelProperties, modelAssociations); }
Example #25
Source File: M2ClassDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModel() { return model; }
Example #26
Source File: M2AssociationDefinition.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ModelDefinition getModel() { return classDef.getModel(); }
Example #27
Source File: RepoModelDefinition.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModel() { return model; }
Example #28
Source File: RepoAdminServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private QName activateOrDeactivate(String modelFileName, boolean activate) { // Check that all the passed values are not null ParameterCheck.mandatoryString("modelFileName", modelFileName); StoreRef storeRef = repoModelsLocation.getStoreRef(); NodeRef rootNode = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repoModelsLocation.getPath()+"//.[@cm:name='"+modelFileName+"' and "+defaultSubtypeOfDictionaryModel+"]", null, namespaceService, false); if (nodeRefs.size() == 0) { throw new AlfrescoRuntimeException(MODEL_NOT_FOUND, new Object[] { modelFileName }); } else if (nodeRefs.size() > 1) { // unexpected: should not find multiple nodes with same name throw new AlfrescoRuntimeException(MODELS_MULTIPLE_FOUND, new Object[] { modelFileName }); } NodeRef modelNodeRef = nodeRefs.get(0); boolean isActive = false; Boolean value = (Boolean)nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE); if (value != null) { isActive = value.booleanValue(); } QName modelQName = (QName)nodeService.getProperty(modelNodeRef, ContentModel.PROP_MODEL_NAME); ModelDefinition modelDef = null; if (modelQName != null) { try { modelDef = dictionaryDAO.getModel(modelQName); } catch (DictionaryException e) { logger.warn(e); } } if (activate) { // activate if (isActive) { if (modelDef != null) { // model is already activated throw new AlfrescoRuntimeException(MODEL_ALREADY_ACTIVATED, new Object[] { modelQName }); } else { logger.warn("Model is set to active but not loaded in Dictionary - trying to load..."); } } else { if (modelDef != null) { logger.warn("Model is loaded in Dictionary but is not set to active - trying to activate..."); } } } else { // deactivate if (!isActive) { if (modelDef == null) { // model is already deactivated throw new AlfrescoRuntimeException(MODEL_ALREADY_DEACTIVATED, new Object[] { modelQName }); } else { logger.warn("Model is set to inactive but loaded in Dictionary - trying to unload..."); } } else { if (modelDef == null) { logger.warn("Model is not loaded in Dictionary but is set to active - trying to deactivate..."); } } } // activate/deactivate the model nodeService.setProperty(modelNodeRef, ContentModel.PROP_MODEL_ACTIVE, new Boolean(activate)); // note: model will be loaded/unloaded as part of DictionaryModelType.beforeCommit() return modelQName; }
Example #29
Source File: AlfrescoModel.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
protected AlfrescoModel(ModelDefinition modelDef) { this.modelDef = modelDef; this.checksum = modelDef.getChecksum(ModelDefinition.XMLBindingType.DEFAULT); }
Example #30
Source File: AlfrescoModel.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public ModelDefinition getModelDef() { return modelDef; }