Search in sources :

Example 1 with DictionaryDAO

use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-remote-api by Alfresco.

the class AbstractEnterpriseOpenCMISTCKTest method overrideVersionableAspectProperties.

protected void overrideVersionableAspectProperties(ApplicationContext ctx) {
    final DictionaryDAO dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    dictionaryDAO.removeModel(QName.createQName("cm:contentmodel"));
    M2Model contentModel = M2Model.createModel(getClass().getClassLoader().getResourceAsStream("alfresco/model/contentModel.xml"));
    M2Aspect versionableAspect = contentModel.getAspect("cm:versionable");
    M2Property prop = versionableAspect.getProperty("cm:initialVersion");
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersion");
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersionOnUpdateProps");
    prop.setDefaultValue(Boolean.FALSE.toString());
    dictionaryDAO.putModel(contentModel);
}
Also used : DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

Example 2 with DictionaryDAO

use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.

the class SiteServiceImplTest method testCustomSiteType.

/**
 * Creates a site with a custom type, and ensures that
 *  it behaves correctly.
 */
@SuppressWarnings("deprecation")
@Test
public void testCustomSiteType() {
    final String CS_URI = "http://example.com/site";
    final String CS_PFX = "cs";
    // Setup our custom site type
    DictionaryDAO dictionaryDAO = (DictionaryDAO) this.applicationContext.getBean("dictionaryDAO");
    M2Model model = M2Model.createModel("cm:CustomSiteModel");
    model.createNamespace(CS_URI, CS_PFX);
    // Import the usual suspects too
    model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
    model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX);
    model.createImport(SiteModel.SITE_MODEL_URL, SiteModel.SITE_MODEL_PREFIX);
    // Custom type
    M2Type customType = model.createType("cs:customSite");
    customType.setTitle("customSite");
    customType.setParentName(SiteModel.SITE_MODEL_PREFIX + ":" + SiteModel.TYPE_SITE.getLocalName());
    M2Property customProp = customType.createProperty("cs:customSiteProp");
    customProp.setTitle("customSiteProp");
    customProp.setType("d:text");
    dictionaryDAO.putModel(model);
    // Get our custom type, to check it's in there properly
    final QName customTypeQ = QName.createQName("cs", "customSite", namespaceService);
    TypeDefinition td = dictionaryService.getType(customTypeQ);
    assertNotNull(td);
    // Create a site
    SiteInfo site = siteService.createSite("custom", "custom", "Custom", "Custom", SiteVisibility.PUBLIC);
    // Check the roles on it
    List<String> roles = siteService.getSiteRoles();
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    roles = siteService.getSiteRoles(site.getShortName());
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    // Swap the type
    nodeService.setType(site.getNodeRef(), customTypeQ);
    // Check again
    roles = siteService.getSiteRoles();
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    roles = siteService.getSiteRoles(site.getShortName());
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    // Alter the permissions for the custom site
    PermissionService testPermissionService = spy((PermissionService) this.applicationContext.getBean("permissionServiceImpl"));
    Set<String> customPerms = new HashSet<String>();
    customPerms.add(SiteServiceImpl.SITE_MANAGER);
    customPerms.add("CUSTOM");
    when(testPermissionService.getSettablePermissions(customTypeQ)).thenReturn(customPerms);
    // Check it changed for the custom site, but not normal
    SiteServiceImpl siteServiceImpl = (SiteServiceImpl) this.applicationContext.getBean("siteService");
    siteServiceImpl.setPermissionService(testPermissionService);
    roles = siteService.getSiteRoles();
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    roles = siteService.getSiteRoles(site.getShortName());
    assertEquals(2, roles.size());
    assertEquals(true, roles.contains("CUSTOM"));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    // Put the permissions back
    siteServiceImpl.setPermissionService(permissionService);
    roles = siteService.getSiteRoles();
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
    roles = siteService.getSiteRoles(site.getShortName());
    assertEquals(7, roles.size());
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONSUMER));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_CONTRIBUTOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_COLLABORATOR));
    assertEquals(true, roles.contains(SiteServiceImpl.SITE_MANAGER));
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) M2Property(org.alfresco.repo.dictionary.M2Property) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) PermissionService(org.alfresco.service.cmr.security.PermissionService) M2Type(org.alfresco.repo.dictionary.M2Type) DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) HashSet(java.util.HashSet) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test)

Example 3 with DictionaryDAO

use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.

the class RhinoScriptTest method setUp.

/*
     * @see junit.framework.TestCase#setUp()
     */
protected void setUp() throws Exception {
    super.setUp();
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("transactionComponent");
    contentService = (ContentService) ctx.getBean("contentService");
    nodeService = (NodeService) ctx.getBean("nodeService");
    scriptService = (ScriptService) ctx.getBean("scriptService");
    serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.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);
    BaseNodeServiceTest.loadModel(ctx);
}
Also used : DictionaryComponent(org.alfresco.repo.dictionary.DictionaryComponent) DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) InputStream(java.io.InputStream) M2Model(org.alfresco.repo.dictionary.M2Model)

Example 4 with DictionaryDAO

use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.

the class ConcurrentNodeServiceSearchTest method setUp.

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();
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) InputStream(java.io.InputStream) M2Model(org.alfresco.repo.dictionary.M2Model)

Example 5 with DictionaryDAO

use of org.alfresco.repo.dictionary.DictionaryDAO in project alfresco-repository by Alfresco.

the class IntegrityTest method setUp.

public void setUp() throws Exception {
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);
    integrityChecker = (IntegrityChecker) ctx.getBean("integrityChecker");
    integrityChecker.setEnabled(true);
    integrityChecker.setFailOnViolation(true);
    integrityChecker.setTraceOn(true);
    // we want to count the correct number of errors
    integrityChecker.setMaxErrorsPerTransaction(100);
    MetadataEncryptor encryptor = (MetadataEncryptor) ctx.getBean("metadataEncryptor");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    this.authenticationComponent.setSystemUserAsCurrentUser();
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef)) {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);
    allProperties = new PropertyMap();
    allProperties.put(TEST_PROP_TEXT_A, "ABC");
    allProperties.put(TEST_PROP_TEXT_B, "DEF");
    allProperties.put(TEST_PROP_INT_A, "123");
    allProperties.put(TEST_PROP_INT_B, "456");
    allProperties.put(TEST_PROP_ENCRYPTED_A, "ABC");
    allProperties.put(TEST_PROP_ENCRYPTED_B, "DEF");
    allProperties = encryptor.encrypt(allProperties);
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) ApplicationContext(org.springframework.context.ApplicationContext) PropertyMap(org.alfresco.util.PropertyMap) DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) TransactionService(org.alfresco.service.transaction.TransactionService) InputStream(java.io.InputStream) MetadataEncryptor(org.alfresco.repo.node.encryption.MetadataEncryptor) M2Model(org.alfresco.repo.dictionary.M2Model)

Aggregations

DictionaryDAO (org.alfresco.repo.dictionary.DictionaryDAO)19 M2Model (org.alfresco.repo.dictionary.M2Model)16 InputStream (java.io.InputStream)13 DictionaryComponent (org.alfresco.repo.dictionary.DictionaryComponent)8 StoreRef (org.alfresco.service.cmr.repository.StoreRef)8 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 QName (org.alfresco.service.namespace.QName)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)3 TransactionService (org.alfresco.service.transaction.TransactionService)3 Before (org.junit.Before)3 ApplicationContext (org.springframework.context.ApplicationContext)3 M2Property (org.alfresco.repo.dictionary.M2Property)2 PermissionService (org.alfresco.service.cmr.security.PermissionService)2 PropertyMap (org.alfresco.util.PropertyMap)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1