cancel
Showing results for 
Search instead for 
Did you mean: 

javascript - copy content problem

friedman30
Champ in-the-making
Champ in-the-making
hi,

I've added some custom types to alfresco. one of them is 'Image' which adds some properties to to the regular 'Content' props.

I need to make a copy of that image (which is an 'Image' type) using javascript API.

I am using the copy method :
document.copy(currentFolder);

which works great - with one major problem - the copy is not just a copy of the image, but a full copy of the properties and type.

I need to make a copy of an image, that will not have the same type of the copied image…..

so, for example, if i have myPic.jpg which is an 'Image' type - i need to create copy of myPic.jpg which is a 'Content' type.

any ideas???
:shock:

thanks,

Dror
8 REPLIES 8

kevinr
Star Contributor
Star Contributor
The JavaScript API supports modification of the object type and setting of various properties and aspects. You can either "specializeType()" the type using that API call and clear the properties you don't want or you can try creating a new object of the desired type (again all the APIs are there - see the examples) and then setting the content property of the destination object to a copy of the source object.

Thanks,

Kevin

friedman30
Champ in-the-making
Champ in-the-making
Hi Kevin,

I've tried using the "specializeType()" method you've suggested on my custom type (which inherits from "cm:content" type).

I've done this:

changeFile = document.copy(currentFolder);
var typeChanged = changeFile.specializeType("cm:content");

i've also tried this:

var typeChanged = changeFile.specializeType("{http://www.alfresco.org/model/content/1.0}content");

* the document that i copy is, of course, a custom-type content.

after running this java script, there is no change in the type of the copied content (typeChanged = false).

  :?

am i doing anything wrong?

thanks,

Dror

friedman30
Champ in-the-making
Champ in-the-making
I looked deeper into "specializeType" method and found that since it uses
"isSubClass" i will always get false. (since i want to convert a type to its parent's class type).

   
public boolean specializeType(String type) {

        ParameterCheck.mandatoryString("Type", type);
        QName qnameType = createQName(type);

        if (getType().equals(qnameType) == false && this.services.getDictionaryService().isSubClass(qnameType, getType()) == true) {
            this.nodeService.setType(this.nodeRef, qnameType);
            this.type = qnameType;
            return true;
        }
        return false;
    }

Is there any way to bypass this ?
:?:

Thanks,

Dror

kevinr
Star Contributor
Star Contributor
No at the moment i don't think there is. I'm not sure what the implication of converting a node from a type to a non-specialised type i.e. not a related type or one that has a sub-set of the properties - i'll try and find out.

Thanks,

Kevin

friedman30
Champ in-the-making
Champ in-the-making
thanks Kevin.

I need to convert the copy of a specific content to another type since in my application i query by type and i don't want to get duplicated results just because i have a copy of a content.

the copy is used to create a thumbnail for every image in the CMS, and if it'll be of the same type it will return in the query as well.

this is why i must convert that copy to a basic type.

hope i made it clear.
:roll:


Best regards ,
Dror

itayh
Champ in-the-making
Champ in-the-making
Hi Kevin,

The JavaScript API supports modification of the object type and setting of various properties and aspects. You can either "specializeType()" the type using that API call and clear the properties you don't want or you can try creating a new object of the desired type (again all the APIs are there - see the examples) and then setting the content property of the destination object to a copy of the source object.

I try to set the content property of the destination object to a copy of the source object using xxx.content = document.content.
For images, Binary thats does not work. Any other way to do that?

itayh
Champ in-the-making
Champ in-the-making
Hi,

One more Q,

I notice the write function in java script API. The wiki say:
write(ScriptContent content)
    Copy the content from the specified ScriptContent (sorry, available from 2.1 Enterprise onwards).

Does the 2.1 Enterprise version is different from 2.1 Community version?

Thx,
Itay

kevinr
Star Contributor
Star Contributor
This function only made it in after 2.1 Community release - however it has already been merged into the community HEAD code stream so is available in public SVN or a nightly build download.

Thanks,

Kevin