07-25-2017 05:00 AM
Hello,
Is there any limitation to insert a thousand number of records into the alfresco aspects?
If not, what is the impact of the following call:
Serializable subscriptionCreated = nodeService.getProperty(companyHome, BluvaltEducationModel.PROP_SUBSCRIPTION_CREATED);Map<String, String> subscribedUsers = new HashMap<String, String>();
subscribedUsers = (Map) subscriptionCreated;
Is java will support it without crashing?
Thank you
Jamil
07-26-2017 05:14 AM
I can't see in your code example where there would be thousands of records...
Generally, there is no technical limit to the number of aspects on a node, or the number of entries in a multiple property value. In your example you are apparently storing a Map as a property value - maps will be stored as binary objects (BLOB) in the database, which may limit some functionality like DB-level querying. I would not use such large maps as values...
07-26-2017 05:46 AM
Here how I read, process then add a new value to the aspect with some comments
Map<String, String> subscribedUsers = new HashMap<String, String>();
//Read the saved aspect
Serializable subscriptionCreatedSer = nodeService.getProperty(companyHome, BluvaltEducationModel.PROP_SUBSCRIPTION_CREATED);
//Cast to Map because the aspect is a Map {String, String}
subscribedUsers = (Map) subscriptionCreatedSer;//search on the Map subscribedUsers and get a value
String subscribedData = subscribedUsers.get("id");
//some processing...
//add new aspect Map value
subscribedUsers.put(key, eventStr); //key is an id, eventStr is a JSON as string
nodeService.setProperty(companyHome, BluvaltEducationModel.PROP_SUBSCRIPTION_CREATED, (Serializable) subscribedUsers);
From the log the print of the aspect content is like this:
14640, {"id": "efcf086e-6364-414b-9068-93c6ba859416", "type": "subscription.created", "service": ...}
23241, {"data":{"end_date":null,"canceled_at":null,"created":"2017-07-25T13:25:04.680649Z","datacenter":...}
14645, {"id": "efcf086e-6364-414b-9068-93c6ba859416", "type": "subscription.created", "service": ...}
23255, {"data":{"end_date":null,"canceled_at":null,"created":"2017-07-25T13:25:04.680649Z","datacenter":...}
14677, {"id": "efcf086e-6364-414b-9068-93c6ba859416", "type": "subscription.created", "service": ...}
23200, {"data":{"end_date":null,"canceled_at":null,"created":"2017-07-25T13:25:04.680649Z","datacenter":...}
14647, {"id": "efcf086e-6364-414b-9068-93c6ba859416", "type": "subscription.created", "service": ...}
23277, {"data":{"end_date":null,"canceled_at":null,"created":"2017-07-25T13:25:04.680649Z","datacenter":...}
I will have a thousand of added aspect and my concern is about the subscribedUsers variable in java
Thank you
Jamil
07-26-2017 06:16 AM
What you are storing is not an aspect - you are storing a single property with a complex value. You are not using the Alfresco data model correctly. The key-value entries in your map should be individual properties in the Alfresco data model...
07-26-2017 07:06 AM
It is a single property with a complex value but inside an aspect
myModel.xml
<aspects>
<aspect name="bm:subscriptionDetails">
<title>Subscription Details</title>
<properties>
<property name="bm:subscriptionCreated">
<title>Subscription Created</title>
<type>d:any</type>
<mandatory>false</mandatory>
</property>
</properties>
</aspect>
</aspects>
Model interface
static final QName ASPECT_SUBSCRIPTION_DETAILS = QName.createQName(BLUVALT_ADAPTER_MODEL_1_0_URI, "subscriptionDetails");
static final QName PROP_SUBSCRIPTION_CREATED = QName.createQName(BLUVALT_ADAPTER_MODEL_1_0_URI, "subscriptionCreated");
So before the code I paste in my last post I am checking if the aspect is there or not. If not, I create it. Then I read the property (the complex value) and I iterate and add to it before I save it again in the property of the aspect:
if(!nodeService.hasAspect(companyHome, BluvaltEducationModel.ASPECT_SUBSCRIPTION_DETAILS)) {//we create it
nodeService.addAspect(companyHome, BluvaltEducationModel.ASPECT_SUBSCRIPTION_DETAILS, new HashMap<QName, Serializable>());
}
Is it okay now? if not what you suggest
Thanks
Jamil
07-26-2017 07:15 AM
Each key-value entry in the map should be a separate property on the aspect. This also allows you to specify proper types for these properties, e.g. instead of d:any you can use d:text for data you know to be text. And you can then also use these properties for querying.
The way you are using the single property now is just like a data dump. You would not need to use Alfresco to do that, and could probably do it more efficiently without it.
Explore our Alfresco products with the links below. Use labels to filter content by product module.