diff --git a/.gitignore b/.gitignore
index 0ba2fa4..e15489f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,6 @@ hs_err_pid*
/target/
alf_data_dev
+
+.idea
+*.iml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 700fa45..9fadf14 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,14 +8,14 @@
org.redpill-linpro.alfresco.numbering
alfresco-numbering
- 1.2.0
+ 1.3.0
Alfresco Numbering
pom
org.alfresco
4.2.f
- 1.7
- 1.7
+ 1.8
+ 1.8
repo
diff --git a/repo/pom.xml b/repo/pom.xml
index eef89f1..6117f33 100644
--- a/repo/pom.xml
+++ b/repo/pom.xml
@@ -3,7 +3,7 @@
org.redpill-linpro.alfresco.numbering
alfresco-numbering
- 1.2.0
+ 1.3.0
alfresco-numbering-repo
jar
@@ -137,6 +137,7 @@
true
+
diff --git a/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponent.java b/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponent.java
index ad06158..7942498 100644
--- a/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponent.java
+++ b/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponent.java
@@ -42,4 +42,24 @@ public interface NumberingComponent {
* @return String
*/
public String getDecoratedNextNumber(final NodeRef nodeRef);
+
+ /**
+ * Get the next number in the sequence based on optionValue
+ *
+ * @param nodeRef
+ * @param optionValue
+ * @return
+ */
+
+ public long getNextNumber(NodeRef nodeRef, String optionValue);
+
+ /**
+ * Get the next number based on optionValue and decorate it
+ *
+ * @param nodeRef
+ * @param optionValue
+ * @return
+ */
+
+ public String getDecoratedNextNumber(NodeRef nodeRef, String optionValue);
}
diff --git a/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponentImpl.java b/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponentImpl.java
index 6be03a3..a230dc3 100644
--- a/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponentImpl.java
+++ b/repo/src/main/java/org/redpill/alfresco/numbering/component/NumberingComponentImpl.java
@@ -110,11 +110,23 @@ public long getNextNumber(final NodeRef nodeRef) {
assertAllowGetNextNumber(nodeRef);
return numberingStorage.getNextNumber(startValue, id);
}
-
+
@Override
+ public long getNextNumber(final NodeRef nodeRef,String subOptionValue) {
+ // assertAllowGetNextNumber(nodeRef,subOptionValue);
+ return numberingStorage.getNextNumber(startValue, id,subOptionValue);
+ }
+
+
+ @Override
public String getDecoratedNextNumber(final NodeRef nodeRef) {
return decorator.decorate(getNextNumber(nodeRef), nodeRef);
}
+
+ @Override
+ public String getDecoratedNextNumber(final NodeRef nodeRef,String subOptionValue) {
+ return decorator.decorate(getNextNumber(nodeRef,subOptionValue), nodeRef);
+ }
public void setRepositoryHelper(Repository repositoryHelper) {
this.repositoryHelper = repositoryHelper;
diff --git a/repo/src/main/java/org/redpill/alfresco/numbering/storage/AttributeNumberingStorageImpl.java b/repo/src/main/java/org/redpill/alfresco/numbering/storage/AttributeNumberingStorageImpl.java
index 8c7f6f6..6390354 100644
--- a/repo/src/main/java/org/redpill/alfresco/numbering/storage/AttributeNumberingStorageImpl.java
+++ b/repo/src/main/java/org/redpill/alfresco/numbering/storage/AttributeNumberingStorageImpl.java
@@ -56,6 +56,39 @@ public Long execute() throws Throwable {
}
+ /**
+ * this method generate the next number based on optionValue, option value is based on selected value from drop down list
+ */
+ @Override
+ public long getNextNumber(final long initialValue, final String ids,final String optionValue) {
+ QName lockName = QName.createQName(ATTR_ID + "." + optionValue + ".lock");
+ jobLockService.getLock(lockName, lockTTL, 100, 100);
+ return retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() {
+ @Override
+ public Long execute() throws Throwable {
+
+ if (!attributeService.exists(ATTR_ID, optionValue)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Creating attribute for counter with id " + ATTR_ID + "." + optionValue + ": " + initialValue);
+ }
+ attributeService.createAttribute(initialValue, ATTR_ID, optionValue);
+ return initialValue;
+ } else {
+ Long attributeValue = (Long) attributeService.getAttribute(ATTR_ID, optionValue);
+
+ attributeService.setAttribute(++attributeValue, ATTR_ID, optionValue);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Increased counter with id " + ATTR_ID + "." + optionValue + " to " + attributeValue);
+ }
+ return attributeValue;
+ }
+ }
+ }, false, true);
+
+ }
+
+
+
public void setJobLockService(JobLockService jobLockService) {
this.jobLockService = jobLockService;
}
diff --git a/repo/src/main/java/org/redpill/alfresco/numbering/storage/NodeNumberingStorageImpl.java b/repo/src/main/java/org/redpill/alfresco/numbering/storage/NodeNumberingStorageImpl.java
index c60e779..beba68a 100644
--- a/repo/src/main/java/org/redpill/alfresco/numbering/storage/NodeNumberingStorageImpl.java
+++ b/repo/src/main/java/org/redpill/alfresco/numbering/storage/NodeNumberingStorageImpl.java
@@ -185,6 +185,99 @@ public Long execute() throws Throwable {
}, false, true);
}
+
+
+
+
+ /**
+ * Create the counter node based on optionValue
+ *
+ * @param initialValue its initial value if node does not exist
+ * @param id the id of the counter
+ * @return NodeRef
+ */
+ protected NodeRef createCounterNode(final long initialValue, final String id,final String optionValue) {
+ String fullyAuthenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME);
+ ChildAssociationRef createNode = nodeService.createNode(getCounterApp(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, id), ContentModel.TYPE_CONTENT);
+ nodeService.setProperty(createNode.getChildRef(), ContentModel.PROP_NAME, optionValue);
+ nodeService.addAspect(createNode.getChildRef(), ContentModel.ASPECT_HIDDEN, null);
+ nodeService.setProperty(createNode.getChildRef(), NUMBERING_PROPERTY, initialValue);
+ AuthenticationUtil.setFullyAuthenticatedUser(fullyAuthenticatedUser);
+ return createNode.getChildRef();
+ }
+
+
+ /**
+ * Get the counter node based on optionValue
+ *
+ * @param initialValue its initial value if node does not exist
+ * @param id the id of the counter
+ * @return NodeRef
+ */
+ protected NodeRef getCounterNode(final long initialValue, final String id,final String optionValue) {
+ NodeRef counterNodeRef = null;
+ if (counterCache.containsKey(optionValue)) {
+ counterNodeRef = counterCache.get(optionValue);
+ //If it has been removed, the remove it from cache
+ if (!nodeService.exists(counterNodeRef)) {
+ counterCache.remove(optionValue);
+ counterNodeRef = null;
+ }
+ }
+ if (counterNodeRef == null) {
+ //The counter was not found in cache, try to fetch it fro mthe repo
+ NodeRef counterAppFolderNodeRef = getCounterApp();
+ List childAssocs = nodeService.getChildAssocs(counterAppFolderNodeRef);
+ QName expectedQname = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, id);
+ for (ChildAssociationRef childAssoc : childAssocs) {
+ Serializable property = nodeService.getProperty(childAssoc.getChildRef(), ContentModel.PROP_NAME);
+ if (optionValue.equals(property)) {
+ counterNodeRef = childAssoc.getChildRef();
+ break;
+ } else {
+ LOG.trace("Id: " + optionValue + ", property:" + property);
+ }
+ }
+
+ if (counterNodeRef == null) {
+ counterNodeRef = createCounterNode(initialValue, optionValue);
+ }
+
+ counterCache.put(optionValue, counterNodeRef);
+ }
+ return counterNodeRef;
+ }
+
+
+ @Override
+ public long getNextNumber(final long initialValue, final String ids,final String optionValue) {
+
+ return retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback() {
+ @Override
+ public Long execute() throws Throwable {
+ behaviourFilter.disableBehaviour();
+ String fullyAuthenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
+ AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.SYSTEM_USER_NAME);
+ try {
+ NodeRef counterNode = getCounterNode(initialValue, optionValue,optionValue);
+ Long counterValue = (Long) nodeService.getProperty(counterNode, NUMBERING_PROPERTY);
+ nodeService.setProperty(counterNode, NUMBERING_PROPERTY, ++counterValue);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Counter " + optionValue + " increased to " + counterValue);
+ }
+ return counterValue;
+
+ } finally {
+ AuthenticationUtil.setFullyAuthenticatedUser(fullyAuthenticatedUser);
+ behaviourFilter.enableBehaviour();
+ }
+ }
+ }, false, false);
+
+ }
+
+
public void setJobLockService(JobLockService jobLockService) {
this.jobLockService = jobLockService;
diff --git a/repo/src/main/java/org/redpill/alfresco/numbering/storage/NumberingStorage.java b/repo/src/main/java/org/redpill/alfresco/numbering/storage/NumberingStorage.java
index deb03bb..173a4a5 100644
--- a/repo/src/main/java/org/redpill/alfresco/numbering/storage/NumberingStorage.java
+++ b/repo/src/main/java/org/redpill/alfresco/numbering/storage/NumberingStorage.java
@@ -16,4 +16,15 @@ public interface NumberingStorage {
* @return long
*/
long getNextNumber(long initialValue, String id);
+
+ /**
+ * Returns the next number in the numbering series based on optionValue from drop down list
+ * @param startValue
+ * @param id
+ * @param optionValue
+ * @return
+ */
+
+ long getNextNumber(long startValue, String id, String optionValue);
+
}
diff --git a/repo/src/test/java/org/redpill/alfresco/numbering/it/component/NumberingComponentIntegrationTest.java b/repo/src/test/java/org/redpill/alfresco/numbering/it/component/NumberingComponentIntegrationTest.java
index 5e2b7eb..2056c29 100644
--- a/repo/src/test/java/org/redpill/alfresco/numbering/it/component/NumberingComponentIntegrationTest.java
+++ b/repo/src/test/java/org/redpill/alfresco/numbering/it/component/NumberingComponentIntegrationTest.java
@@ -61,6 +61,8 @@ public void testPrefixNumbering() {
String expected = "D-"+(nextNumber+1);
assertEquals(expected, decoratedNextNumber);
}
+
+
@Test
public void testCurrentDatePrefixNumbering() {
@@ -74,6 +76,15 @@ public void testCurrentDatePrefixNumbering() {
assertEquals(expected, decoratedNextNumber);
}
+ @Test
+ @Repeat(value = REPEAT)
+ public void testDropDownNumbering() {
+ long currentNumber = numberingComponent.getNextNumber(uploadDocument.getNodeRef(),"100");
+ long nextNumber = numberingComponent.getNextNumber(uploadDocument.getNodeRef(),"100");
+ assertEquals("Expected the next number " + nextNumber + " to be greater than the current number " + currentNumber, currentNumber + 1, nextNumber);
+ }
+
+
@Test
@Repeat(value = REPEAT)
public void testNumbering() {