|
3 | 3 | import java.io.Serializable;
|
4 | 4 | import java.util.HashMap;
|
5 | 5 | import java.util.Map;
|
| 6 | +import java.util.Properties; |
6 | 7 | import org.alfresco.model.ContentModel;
|
7 | 8 | import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator;
|
8 | 9 | import org.alfresco.repo.nodelocator.NodeLocatorService;
|
|
14 | 15 | import org.alfresco.service.namespace.QName;
|
15 | 16 | import org.springframework.beans.factory.InitializingBean;
|
16 | 17 | import org.springframework.beans.factory.annotation.Autowired;
|
| 18 | +import org.springframework.beans.factory.annotation.Qualifier; |
17 | 19 | import org.springframework.stereotype.Component;
|
18 | 20 |
|
19 | 21 | @Component
|
20 | 22 | public class Bootstrap implements InitializingBean {
|
21 | 23 |
|
22 | 24 | public static final String WELL_KNOWN_TESTNODE_NAME = "well-known-testnode";
|
| 25 | + private static final String ENABLED_GLOBAL_PROPERTIES_KEY = "eu.xenit.apix.integrationtest.bootstrap.enabled"; |
23 | 26 |
|
24 | 27 | private RetryingTransactionHelper transactionHelper;
|
25 | 28 | private NodeLocatorService nodeLocator;
|
26 | 29 | private NodeService nodeService;
|
| 30 | + private Properties globalProperties; |
27 | 31 |
|
28 | 32 | @Autowired
|
29 | 33 | public Bootstrap(
|
30 | 34 | RetryingTransactionHelper retryingTransactionHelper,
|
31 | 35 | NodeLocatorService nodeLocatorService,
|
32 |
| - NodeService nodeService |
| 36 | + NodeService nodeService, |
| 37 | + @Qualifier("global-properties") Properties globalProperties |
33 | 38 | ) {
|
34 | 39 | this.transactionHelper = retryingTransactionHelper;
|
35 | 40 | this.nodeLocator = nodeLocatorService;
|
36 | 41 | this.nodeService = nodeService;
|
| 42 | + this.globalProperties = globalProperties; |
37 | 43 | }
|
38 | 44 |
|
39 | 45 | @Override
|
40 | 46 | public void afterPropertiesSet() throws Exception {
|
41 |
| - AuthenticationUtil.runAsSystem( |
42 |
| - () -> transactionHelper.doInTransaction( |
43 |
| - () -> { |
44 |
| - NodeRef companyHome = nodeLocator.getNode(CompanyHomeNodeLocator.NAME, null, null); |
45 |
| - NodeRef wellKnownTestNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, WELL_KNOWN_TESTNODE_NAME); |
46 |
| - if (wellKnownTestNode == null) { |
47 |
| - Map<QName, Serializable> folderProperties = new HashMap<>(); |
48 |
| - folderProperties.put(ContentModel.PROP_NAME, WELL_KNOWN_TESTNODE_NAME); |
49 |
| - folderProperties.put(ContentModel.PROP_NODE_UUID, WELL_KNOWN_TESTNODE_NAME); |
50 |
| - nodeService.createNode( |
51 |
| - companyHome, |
52 |
| - ContentModel.ASSOC_CONTAINS, |
53 |
| - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, WELL_KNOWN_TESTNODE_NAME), |
54 |
| - ContentModel.TYPE_FOLDER, |
55 |
| - folderProperties |
56 |
| - ); |
57 |
| - } |
58 |
| - return null; |
59 |
| - }, |
60 |
| - false, |
61 |
| - true |
62 |
| - ) |
63 |
| - ); |
| 47 | + if (Boolean.parseBoolean(globalProperties.getProperty(ENABLED_GLOBAL_PROPERTIES_KEY))) { |
| 48 | + AuthenticationUtil.runAsSystem( |
| 49 | + () -> transactionHelper.doInTransaction( |
| 50 | + () -> { |
| 51 | + NodeRef companyHome = nodeLocator.getNode(CompanyHomeNodeLocator.NAME, null, null); |
| 52 | + NodeRef wellKnownTestNode = nodeService.getChildByName(companyHome, |
| 53 | + ContentModel.ASSOC_CONTAINS, WELL_KNOWN_TESTNODE_NAME); |
| 54 | + if (wellKnownTestNode == null) { |
| 55 | + Map<QName, Serializable> folderProperties = new HashMap<>(); |
| 56 | + folderProperties.put(ContentModel.PROP_NAME, WELL_KNOWN_TESTNODE_NAME); |
| 57 | + folderProperties.put(ContentModel.PROP_NODE_UUID, WELL_KNOWN_TESTNODE_NAME); |
| 58 | + nodeService.createNode( |
| 59 | + companyHome, |
| 60 | + ContentModel.ASSOC_CONTAINS, |
| 61 | + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, |
| 62 | + WELL_KNOWN_TESTNODE_NAME), |
| 63 | + ContentModel.TYPE_FOLDER, |
| 64 | + folderProperties |
| 65 | + ); |
| 66 | + } |
| 67 | + return null; |
| 68 | + }, |
| 69 | + false, |
| 70 | + true |
| 71 | + ) |
| 72 | + ); |
| 73 | + } |
64 | 74 | }
|
65 | 75 | }
|
0 commit comments