cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot create a Folder in a Store

doblek
Champ in-the-making
Champ in-the-making
Hi all,

I'm trying to create a new folder in a recently created store.
My intention is to have the following structure:
personal(Store)
|
|- folder1

|
|- folderN

Once I've created the store and got its root node, I have the following code in order to create the folder:

//Create a new folder (child of root node in store)
trace += "Step 4: creating a folder in the store.<BR>";
//Create reference to the store where this folder is going to be placed. This folder hangs from the root node as its child.
ParentReference parent_folder_ref = new ParentReference(almacen, almacen_root.getUuid(), null, Constants.ASSOC_CHILDREN, "{user_folder}"+folder_name);
trace += " parent reference created<BR>";
NamedValue[] folder_properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, folder_name, null)};
trace += " folder properties array created<BR>";
//Create the command
CMLCreate create_folder = new CMLCreate("user_folder_"+folder_name, parent_folder_ref, Constants.TYPE_FOLDER, folder_properties);
trace += " command created<BR>";
//Execute the command
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create_folder});
trace += " command executed<BR>";

where
    almacen is the Store object
    almacen_root is the reference to its root node
However, though I reach every trace I put, the folder is not created… or at least, I can't see any child in the "Alfresco Node Browser" for that store…
What I'm doing wrong?

On the other hand, where can I find an API (or something similar) for the web services? I feel like I'm not using ParentReference constructor properly…

And finally, what I must do in order to make this folder only accessible for an specific user? Should I add another property to the NamedValue array?

Thanks in advance.

Regards,
Enrique

PS: sorry for my English
3 REPLIES 3

fchevance
Champ in-the-making
Champ in-the-making
Hello,

I think your ParentReference is not correct.
Try using ASSOC_CONTAINS instead of ASSOC_CHILDREN.

ParentReference parent_folder_ref = new ParentReference(almacen, almacen_root.getUuid(), null, Constants.ASSOC_CONTAINS, "{user_folder}"+folder_name); 

Fred

doblek
Champ in-the-making
Champ in-the-making
Hi,

I've tested the solution Fred suggested me (thanks Fred), but I got the same result… =/ Nothing is created in the store…

This is my new code:

//Create a new folder (child of root node in store)
trace += "Step 4: creating a folder in the store.<BR>";
//Create reference to the store where this folder is going to be placed. This folder hangs from the root node as its child.
ParentReference parent_folder_ref = new ParentReference(almacen, almacen_root.getUuid(), null, Constants.ASSOC_CONTAINS, "{user_folder}"+folder_name);
trace += " parent reference created: "+almacen_root.getUuid()+" ·:· "+folder_name+"<BR>";

NamedValue[] folder_properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, folder_name, null)};
trace += " folder properties array created<BR>";

//Create the command (based on the previous reference)
CMLCreate create_folder = new CMLCreate("user_folder_"+folder_name, parent_folder_ref, Constants.TYPE_FOLDER, folder_properties);
trace += " command created<BR>";

//Execute the command
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create_folder});
trace += " command executed<BR>";

As far as I know from the traces I put (this time I was trying to create a folder called "jonas" in store "personal"):
Starting web service…
Step 1: logged in as admin user.
Step 2: checking for existing previous stores…
store(0): alfrescoUserStore
store(1): system
store(2): lightWeightVersionStore
store(3): SpacesStore
store(4): SpacesStore
store(5): personal
The store does exist. So we retrieve it.
The store is: personal
Step 3: looking for the root node in the store.
Founded 1 nodes in the store "personal"
Root founded: org.alfresco.webservice.types.Reference@1a5f1cc5
Step 4: creating a folder in the store.
parent reference created: 081690f5-6505-11db-b0c1-a302df063455 ·:· jonas
folder properties array created
command created
command executed
everything went fine.

However, Alfresco Node Browser still says that "personal" store does not contain anything…
Node Identifier Primary Path: / 
Reference: workspace://personal/081690f5-6505-11db-b0c1-a302df063455
Type: {http://www.alfresco.org/model/system/1.0}store_root
Parent: 

Properties Name Value Property Type Value Type Residual
{http://www.alfresco.org/model/system/1.0}store-protocol workspace
{ http://www.alfresco.org/model/dictionary/1.0}text 
false
{http://www.alfresco.org/model/content/1.0}name 081690f5-6505-11db-b0c1-a302df063455
{ http://www.alfresco.org/model/dictionary/1.0}text 
false
{http://www.alfresco.org/model/system/1.0}node-uuid 081690f5-6505-11db-b0c1-a302df063455
{http://www.alfresco.org/model/dictionary/1.0}text 
false
{ http://www.alfresco.org/model/system/1.0}store-identifier personal
{http://www.alfresco.org/model/dictionary/1.0}text 
false
{ http://www.alfresco.org/model/system/1.0}node-dbid 407
{http://www.alfresco.org/model/dictionary/1.0}long 
false

Aspects {http://www.alfresco.org/model/system/1.0}aspect_root

Permissions Inherit: true

Assigned Permission To Authority Access

Children Child Name Child Node Primary Association Type Index

Associations To Node Association Type

Parents Child Name Parent Node Primary Association Type

Do I have to create a new node for each folder (which is a child of the root node of the store) through a "child association" and then create a folder in this new node (through a "contain association")?

But, in any case, I should see a folder called "jonas" hanging on root node… and as far as I know, "personal" store does not contain anything…

Could it be a problem with the path(which is "null") or the name when creating the ParentReference object?

Any help would be very much appreciatted 😃

Thanks again,
Enrique

doblek
Champ in-the-making
Champ in-the-making
Hi,

It was my mistake…  Smiley Surprisedops:
The line I thought it was executing the CML command, it actually does not do that… it's just part of the creation of the command…
The CML command executes when updating the repository…

Now that I have this code:

//Create a new folder (child of root node in store)
//Create reference to the store where this folder is going to be placed. This folder hangs from the root node as its child.
ParentReference parent_folder_ref = new ParentReference(almacen, almacen_root.getUuid(), null, Constants.ASSOC_CONTAINS, "{user_folder}"+folder_name);
trace += " parent reference created:<BR>";
NamedValue[] folder_properties = new NamedValue[]{new NamedValue(Constants.PROP_NAME, false, folder_name, null)};

//Create the command (based on the previous reference)
CMLCreate create_folder = new CMLCreate(folder_name, parent_folder_ref, Constants.TYPE_FOLDER, folder_properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create_folder});
trace += " command created<BR>";

//Execute the command
WebServiceFactory.getRepositoryService().update(cml);    //This is the missing line

I see some changes expected in Alfresco:
Node Identifier Primary Path: / 
Reference: workspace://personal/a0bb0866-6e81-11db-b14b-fbaff357da54
Type: {http://www.alfresco.org/model/system/1.0}store_root
Parent: 

[…]

Children Child Name Child Node Primary Association Type Index
{user_folder}jonas workspace://personal/63f80dac-6f4c-11db-8930-df44c0173c45 true {http://www.alfresco.org/model/content/1.0}contains 0
{user_folder}jonas workspace://personal/65ed58d3-6f4d-11db-9132-2fa3219893eb true {http://www.alfresco.org/model/content/1.0}contains 1

Though I don't see why Alfresco has let me create two folders very similar (if not equal)… I have to study this more deeply because now I see in Tomcat's log a warning from the "node integrity checker", letting me know that it has found 2 integrity violations (Duplicate child associations are not allowed). So I suppose I've tried to create three folders with the same name…

Anyway, I've managed to create the folder 😃

My question now is… how can I navigate to that folder?

Regards,
Enrique