List<NodeRef> nodeRefs = searchService.selectNodes(getRootNode(), builder.toString(), null, namespaceDAO, false, SearchService.LANGUAGE_XPATH); M2Model m2Model = getM2Model(nodeRef); if (m2Model == null) continue; result.add(compileModel(m2Model));
@Override public CustomModelDefinition createCustomModel(M2Model m2Model, boolean activate) { ParameterCheck.mandatory("m2Model", m2Model); String modelName = m2Model.getName(); int colonIndex = modelName.indexOf(QName.NAMESPACE_PREFIX); final String modelFileName = (colonIndex == -1) ? modelName : modelName.substring(colonIndex + 1); if (isModelExists(modelFileName)) { throw new CustomModelException.ModelExistsException(MSG_NAME_ALREADY_IN_USE, new Object[] { modelFileName }); } // Validate the model namespace URI validateModelNamespaceUri(getModelNamespaceUriPrefix(m2Model).getFirst()); // Validate the model namespace prefix validateModelNamespacePrefix(getModelNamespaceUriPrefix(m2Model).getSecond()); // Return the created model definition CompiledModel compiledModel = createUpdateModel(modelFileName, m2Model, activate, MSG_CREATE_MODEL_ERR, false); CustomModelDefinition modelDef = new CustomModelDefinitionImpl(compiledModel, activate, dictionaryService); if (logger.isDebugEnabled()) { logger.debug(modelFileName + " model has been created."); } return modelDef; }
/** * Creates a copy of the custom model where the created node will be a child * of download container. * * @param newName the model new name * @param modelNodeRef existing model nodeRef * @return the created nodeRef */ protected NodeRef createCustomModelCopy(final String newName, final NodeRef modelNodeRef) { return doInTransaction(MSG_DOWNLOAD_COPY_MODEL_ERR, true, new RetryingTransactionCallback<NodeRef>() { @Override public NodeRef execute() throws Exception { final NodeRef newNodeRef = createDownloadTypeNode(newName); Serializable content = nodeService.getProperty(modelNodeRef, ContentModel.PROP_CONTENT); nodeService.setProperty(newNodeRef, ContentModel.PROP_CONTENT, content); return newNodeRef; } }); }
@Override public PagingResults<CustomModelDefinition> getCustomModels(PagingRequest pagingRequest) { ParameterCheck.mandatory("pagingRequest", pagingRequest); List<CustomModelDefinition> result = getAllCustomModels(); return result.isEmpty() ? new EmptyPagingResults<CustomModelDefinition>() : wrapResult(pagingRequest, result); }
private CompiledModel getModelByUri(String uri) { for (CompiledModel model : getAllCustomM2Models(false)) { if (uri.equals(getModelNamespaceUriPrefix(model.getM2Model()).getFirst())) { return model; } } return null; }
@Override public PagingResults<AspectDefinition> getAllCustomAspects(PagingRequest pagingRequest) { ParameterCheck.mandatory("pagingRequest", pagingRequest); List<AspectDefinition> result = new ArrayList<>(); List<CompiledModel> list = getAllCustomM2Models(false); for (CompiledModel model : list) { result.addAll(model.getAspects()); } return wrapResult(pagingRequest, result); }
final NodeRef existingModelNodeRef = getModelNodeRef(modelFileName); if (existingModelNodeRef == null) final M2Model existingModel = getM2Model(existingModelNodeRef); final Pair<String, String> existingNamespacePair = getModelNamespaceUriPrefix(existingModel); final Pair<String, String> newNamespacePair = getModelNamespaceUriPrefix(m2Model); validateModelNamespacePrefix(newNamespacePair.getSecond()); validateModelNamespaceUri(newNamespacePair.getFirst()); CompiledModel compiledModel = createUpdateModel(modelFileName, m2Model, activate, MSG_UPDATE_MODEL_ERR, true); CustomModelDefinition modelDef = new CustomModelDefinitionImpl(compiledModel, activate, dictionaryService);
@Override public void deactivateCustomModel(final String modelName) CustomModelDefinition customModelDefinition = getCustomModel(modelName); if (customModelDefinition == null) Collection<AspectDefinition> modelAspects = customModelDefinition.getAspectDefinitions(); for (CompiledModel cm : getAllCustomM2Models(false)) validateTypeAspectDependency(modelTypes, cm.getTypes()); validateTypeAspectDependency(modelAspects, cm.getAspects()); doInTransaction(MSG_UNABLE_MODEL_DEACTIVATE, true, new RetryingTransactionCallback<Void>()
private CompiledModel createUpdateModel(final String modelFileName, final M2Model m2Model, final boolean activate, String errMsgId, boolean requiresNewTx) { // Validate model CompiledModel compiledModel = compileModel(m2Model); // Validate properties default values validatePropsDefaultValues(compiledModel); ByteArrayOutputStream xml = new ByteArrayOutputStream(); m2Model.toXML(xml); final InputStream modelStream = new ByteArrayInputStream(xml.toByteArray()); // Create the model node NodeRef nodeRef = doInTransaction(errMsgId, requiresNewTx, new RetryingTransactionCallback<NodeRef>() { public NodeRef execute() throws Exception { return repoAdminService.deployModel(modelStream, modelFileName, activate); } }); if (!nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_MODEL)) { // Add the 'customModelManagement' marker aspect, to // indicate that this model has been created dynamically by this service nodeService.addAspect(nodeRef, ASPECT_CUSTOM_MODEL, null); } // Add hidden aspect if (!hiddenAspect.hasHiddenAspect(nodeRef)) { hiddenAspect.hideNode(nodeRef, false, false, false); } return compiledModel; }
final NodeRef modelNodeRef = getModelNodeRef(modelName); model = getM2Model(modelNodeRef); Pair<CompiledModel, Boolean> result = (model == null) ? null : new Pair<>(compileModel(model), isActive);
NodeRef customModelNodeRef = getModelNodeRef(modelFileName); if(customModelNodeRef == null) customModelNodeRef = createCustomModelCopy(modelFileName + ".xml", customModelNodeRef); nodesToBeDownloaded.add(customModelNodeRef); try shareExtModuleNodeRef = createCustomModelShareExtModuleRef(modelFileName); nodesToBeDownloaded.add(shareExtModuleNodeRef);
final NodeRef formNodeRef = getShareExtModule(); ContentReader reader = contentService.getReader(formNodeRef, ContentModel.PROP_CONTENT); return doInTransaction(MSG_DOWNLOAD_CREATE_SHARE_EXT_ERR, true, new RetryingTransactionCallback<NodeRef>()
@Override public CustomModelDefinition getCustomModel(String modelName) { ParameterCheck.mandatoryString("modelName", modelName); Pair<CompiledModel, Boolean> compiledModelPair = getCustomCompiledModel(modelName); CustomModelDefinition result = (compiledModelPair == null) ? null : new CustomModelDefinitionImpl( compiledModelPair.getFirst(), compiledModelPair.getSecond(), dictionaryService); return result; }
@Override public CustomModelsInfo getCustomModelsInfo() { List<CustomModelDefinition> page = getCustomModels(new PagingRequest(0, Integer.MAX_VALUE)).getPage(); int activeModels = 0; int activeTypes = 0; int activeAspects = 0; for (CustomModelDefinition cm : page) { if (cm.isActive()) { activeModels++; activeTypes += cm.getTypeDefinitions().size(); activeAspects += cm.getAspectDefinitions().size(); } } CustomModelsInfo info = new CustomModelsInfo(); info.setNumberOfActiveModels(activeModels); info.setNumberOfActiveTypes(activeTypes); info.setNumberOfActiveAspects(activeAspects); return info; } }
protected List<CustomModelDefinition> getAllCustomModels() { List<CustomModelDefinition> result = new ArrayList<>(); Collection<QName> models = dictionaryDAO.getModels(true); List<String> dictionaryModels = new ArrayList<>(); for (QName model : models) { dictionaryModels.add(model.toPrefixString()); } List<CompiledModel> compiledModels = getAllCustomM2Models(false); if (compiledModels.size() > 0) { for (CompiledModel model : compiledModels) { // check against models loaded in dictionary boolean isActive = false; if (dictionaryModels.contains(model.getM2Model().getName())) { isActive = true; } result.add(new CustomModelDefinitionImpl(model, isActive, dictionaryService)); } } return result; }
final NodeRef existingModelNodeRef = getModelNodeRef(modelFileName); if (existingModelNodeRef == null) final M2Model existingModel = getM2Model(existingModelNodeRef); final Pair<String, String> existingNamespacePair = getModelNamespaceUriPrefix(existingModel); final Pair<String, String> newNamespacePair = getModelNamespaceUriPrefix(m2Model); validateModelNamespacePrefix(newNamespacePair.getSecond()); validateModelNamespaceUri(newNamespacePair.getFirst()); CompiledModel compiledModel = createUpdateModel(modelFileName, m2Model, activate, MSG_UPDATE_MODEL_ERR, true); CustomModelDefinition modelDef = new CustomModelDefinitionImpl(compiledModel, activate, dictionaryService);
@Override public void deactivateCustomModel(final String modelName) CustomModelDefinition customModelDefinition = getCustomModel(modelName); if (customModelDefinition == null) Collection<AspectDefinition> modelAspects = customModelDefinition.getAspectDefinitions(); for (CompiledModel cm : getAllCustomM2Models(false)) validateTypeAspectDependency(modelTypes, cm.getTypes()); validateTypeAspectDependency(modelAspects, cm.getAspects()); doInTransaction(MSG_UNABLE_MODEL_DEACTIVATE, true, new RetryingTransactionCallback<Void>()
private CompiledModel getModelByUri(String uri) { for (CompiledModel model : getAllCustomM2Models(false)) { if (uri.equals(getModelNamespaceUriPrefix(model.getM2Model()).getFirst())) { return model; } } return null; }
private CompiledModel createUpdateModel(final String modelFileName, final M2Model m2Model, final boolean activate, String errMsgId, boolean requiresNewTx) { // Validate model CompiledModel compiledModel = compileModel(m2Model); // Validate properties default values validatePropsDefaultValues(compiledModel); ByteArrayOutputStream xml = new ByteArrayOutputStream(); m2Model.toXML(xml); final InputStream modelStream = new ByteArrayInputStream(xml.toByteArray()); // Create the model node NodeRef nodeRef = doInTransaction(errMsgId, requiresNewTx, new RetryingTransactionCallback<NodeRef>() { public NodeRef execute() throws Exception { return repoAdminService.deployModel(modelStream, modelFileName, activate); } }); if (!nodeService.hasAspect(nodeRef, ASPECT_CUSTOM_MODEL)) { // Add the 'customModelManagement' marker aspect, to // indicate that this model has been created dynamically by this service nodeService.addAspect(nodeRef, ASPECT_CUSTOM_MODEL, null); } // Add hidden aspect if (!hiddenAspect.hasHiddenAspect(nodeRef)) { hiddenAspect.hideNode(nodeRef, false, false, false); } return compiledModel; }
final NodeRef modelNodeRef = getModelNodeRef(modelName); model = getM2Model(modelNodeRef); Pair<CompiledModel, Boolean> result = (model == null) ? null : new Pair<>(compileModel(model), isActive);