private M2Model getM2Model(final NodeRef modelNodeRef) { ContentReader reader = contentService.getReader(modelNodeRef, ContentModel.PROP_CONTENT); if (reader == null) { return null; } InputStream in = reader.getContentInputStream(); try { return M2Model.createModel(in); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.error("Failed to close input stream for " + modelNodeRef); } } } }
private M2Model getM2Model(final NodeRef modelNodeRef) { ContentReader reader = contentService.getReader(modelNodeRef, ContentModel.PROP_CONTENT); if (reader == null) { return null; } InputStream in = reader.getContentInputStream(); try { return M2Model.createModel(in); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.error("Failed to close input stream for " + modelNodeRef); } } } }
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); } }
private void addTypeTestDataModel() { // load in the test model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("org/alfresco/cmis/search/CMIS-query-test-model.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDAO.putModel(model); ((CMISAbstractDictionaryService) cmisDictionaryService).afterDictionaryDestroy(); ((CMISAbstractDictionaryService) cmisDictionaryService).afterDictionaryInit(); }
public AlfrescoModel getModel(String coreName, QName modelName) throws AuthenticationException, IOException, JSONException { // If the model is new to the SOLR side the prefix will be unknown so we can not generate prefixes for the request! // Always use the full QName with explicit URI StringBuilder url = new StringBuilder(GET_MODEL); URLCodec encoder = new URLCodec(); // must send the long name as we may not have the prefix registered url.append("?modelQName=").append(encoder.encode(modelName.toString(), "UTF-8")); GetRequest req = new GetRequest(url.toString()); Response response = null; try { response = repositoryHttpClient.sendRequest(req); if(response.getStatus() != HttpStatus.SC_OK) { throw new AlfrescoRuntimeException(coreName + " GetModel return status is " + response.getStatus()); } return new AlfrescoModel(M2Model.createModel(response.getContentAsStream()), Long.valueOf(response.getHeader(CHECKSUM_HEADER))); } finally { if(response != null) { response.release(); } } }
@Before public void before() throws Exception { mlAwareNodeService = (NodeService) applicationContext.getBean("mlAwareNodeService"); nodeService = (NodeService) applicationContext.getBean("nodeService"); dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); authenticationComponent.setSystemUserAsCurrentUser(); ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/NodeRefTestModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDAO.putModel(model); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); }
@Override public Void doWork() throws Exception { M2Model customModel = M2Model.createModel( Thread.currentThread().getContextClassLoader(). getResourceAsStream("dictionary/dictionarydaotest_model1.xml")); dictionaryDAO.putModel(customModel); assertNotNull(cmisDictionaryService.findType("P:cm:dublincore")); TypeDefinitionWrapper td = cmisDictionaryService.findType("D:daotest1:type1"); assertNotNull(td); return null; } }, "user1", "tenant1");
/** * Loads the test model required for building the node graphs */ public static DictionaryService loadModel(ApplicationContext applicationContext) { DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); // load the system model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); DictionaryComponent dictionary = new DictionaryComponent(); dictionary.setDictionaryDAO(dictionaryDao); // done return dictionary; } /**
/** * Loads the test model required for building the node graphs */ public static DictionaryService loadModel(ApplicationContext applicationContext) { DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); // load the system model ClassLoader cl = PerformanceNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); DictionaryComponent dictionary = new DictionaryComponent(); dictionary.setDictionaryDAO(dictionaryDao); return dictionary; }
protected void loadTestModel() { ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/search/impl/MetadataQueryTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDAO.registerListener(this); dictionaryDAO.reset(); assertNotNull(dictionaryDAO.getClass(TEST_SUPER_CONTENT_TYPE)); }
/** * Loads the test model required for building the node graphs */ public static DictionaryService loadModel(ApplicationContext applicationContext) { DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); // load the system model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); DictionaryComponent dictionary = new DictionaryComponent(); dictionary.setDictionaryDAO(dictionaryDao); // done return dictionary; }
InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model);
@Override public Void doWork() throws Exception { M2Model customModel = M2Model.createModel( Thread.currentThread().getContextClassLoader(). getResourceAsStream("dictionary/dictionarydaotest_model1.xml")); dictionaryDAO.putModel(customModel); assertNotNull(service.getType(ContentModel.TYPE_CONTENT)); QName qname = QName.createQName("{http://www.alfresco.org/test/dictionarydaotest1/1.0}type1"); TypeDefinition td = service.getType(qname); assertNotNull(td); return null; } }, "user1", "tenant1");
InputStream modelStream = cl.getResourceAsStream("alfresco/model/contentModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model);
protected void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(); DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO"); // load the system model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); // load the test model modelStream = cl.getResourceAsStream("org/alfresco/repo/node/BaseNodeServiceTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); nodeService = (NodeService) ctx.getBean("dbNodeService"); transactionService = (TransactionService) ctx.getBean("transactionComponent"); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); this.authenticationComponent.setSystemUserAsCurrentUser(); // create a first store directly UserTransaction tx = transactionService.getUserTransaction(); tx.begin(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); tx.commit(); }
InputStream modelStream = cl.getResourceAsStream("alfresco/model/systemModel.xml"); assertNotNull(modelStream); M2Model model = M2Model.createModel(modelStream); dictionaryDao.putModel(model); model = M2Model.createModel(modelStream); dictionaryDao.putModel(model);
@Test public void testListTypesAspects_Empty() throws Exception { final String modelName = makeUniqueName("testCustomModel"); Pair<String, String> namespacePair = getTestNamespacePrefixPair(); final M2Model model = M2Model.createModel(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + modelName); model.createNamespace(namespacePair.getFirst(), namespacePair.getSecond()); createModel(model, false); // Retrieve the created model CustomModelDefinition modelDefinition = getModel(modelName); assertNotNull(modelDefinition); assertEquals(modelName, modelDefinition.getName().getLocalName()); // List all of the model's types Collection<TypeDefinition> types = modelDefinition.getTypeDefinitions(); assertEquals(0, types.size()); // List all of the model's aspects Collection<AspectDefinition> aspects = modelDefinition.getAspectDefinitions(); assertEquals(0, aspects.size()); }
private QName addModel() { this.testNamespace = "http://www.alfresco.org/test/" + modelName; this.modelQName = QName.createQName(testNamespace, modelName); // Create a model this.model = M2Model.createModel(modelName + ":" + modelName); model.createNamespace(testNamespace, modelName); model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, "d"); model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX); this.typeQName = QName.createQName(testNamespace, "type1"); this.type = model.createType(modelName + ":" + typeQName.getLocalName()); type.setParentName("cm:folder"); this.propertyQName = QName.createQName(testNamespace, "prop1"); this.property = type.createProperty(modelName + ":" + propertyQName.getLocalName()); property.setType("d:text"); dictionaryDAO.putModel(model); return modelQName; }
@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()); }
private void createTestModel() M2Model model = M2Model.createModel("test:comparepropertyvalueevaluatortest"); model.createNamespace(TEST_TYPE_NAMESPACE, "test"); model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX);