Forge-Import-Tool: Cusomising the import of binaries using a java class

62 views
Skip to first unread message

Sebastian

unread,
Jul 3, 2014, 12:12:18 PM7/3/14
to hippo-c...@googlegroups.com
Hi there,

in our project we need to import pictures. The pictures are delivered in the following format: ourcompanysname-productgroup-seperated-with-minuses-productnumber.jpg.

What we need is to extract the product number of the picture's name and group the imported pictures in hippo by it. For example, the above picture should be imported to /content/gallerys/de/productgroup-seperated-with-minuses/ourcompanysname-productgroup-seperated-with-minuses-productnumber.jpg. The example-application uses a DemoTestBean which imports XML-Files on a custom way. Is there maybe a way to use a java class for a custom picture import, too? This would even be great for future customizations.

Thanks and kind regards,
Sebastian

Gerard Klijs

unread,
Jul 3, 2014, 12:29:34 PM7/3/14
to hippo-c...@googlegroups.com
The import-tool using spring to a high degree, so it's relatively simple to change one or more classes for custom ones. I don't think the need to rename the pictures that way is very generic, I for example extended the org.onehippo.forge.migration.DocumentCreator to create all the renderings we used in out project, inside this class is the createImageBinary method, which creates the node for the image, so you would like to change it. In your applicationContext.xml you have to put you created class, by using something like:

<bean id="documentCreator" class="com.package.CustomDocumentCreator" init-method="initialize" destroy-method="close">
<constructor-arg type="java.lang.String" value="${import.repository.address}"/>
<constructor-arg type="java.lang.String" value="${import.repository.username}"/>
<constructor-arg type="java.lang.String" value="${import.repository.password}"/>
<property name="configuration" ref="configuration"/>
<property name="stats" ref="stats"/>
</bean>

good luck


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Sebastian

unread,
Jul 7, 2014, 8:08:30 AM7/7/14
to hippo-c...@googlegroups.com, g.k...@gmail.com
Hey Gerard,

thank you for your answer. It worked really great. I will now try to write my own DocumentCreator class.

Im new to Hippo, J2EE and Spring development. For you this may be basic knowledge, but for me it isn't. So your Information is quite helpful for me and I really appreciate it. Thank you a lot.

Kind regards,
Sebastian

Sebastian

unread,
Jul 9, 2014, 3:34:50 AM7/9/14
to hippo-c...@googlegroups.com
Hi there,

I have another question.

In the config file of my application (import-application.properties) I have the following configuration:

import.repository.address = vm://
import.repository.username = admin
import.repository.password = admin
import.signal.inbox = ${catalina.base}/webapps/import-admin/WEB-INF/import-inbox
import.signal.file.includes = import.start
import.signal.direct.start = import.start
import.data.base.path = file:///D:/Projekte/test_images
import.data.binary.base.path = ${import.data.base.path}
import.repository.document.base.path = /content/gallery/imported_product_pictures

So the images I would like to import are located under "D:\Projekte\test_images" and I would like to import them to "/conent/gallery/imported_product_pictures".

With the above configuration the images are imported to "/content/gallery/Projekte/test_images".

This is because of the following method that is part of the class BinaryFile:

    private String createFullPath() {
       
String path = FileUtils.getAbsolutePath(file);
        path
= path.replace(config.getBinaryStripPath(), ""); // TOLATER: method for stripping different from above.

       
// on Windows the path will have backslashes which are not JCR path
       
// separators
        path
= path.replaceAll("\\\\", "/");

       
if (imageType) {
           
return FileUtils.getFileFolder(IMAGE_PREFIX + StringUtils.removeStart(path, "/"), path);
       
}
       
return FileUtils.getFileFolder(ASSET_PREFIX + StringUtils.removeStart(path, "/"), path);
   
}

The method takes the absoulte path, cuts the drive key and adds the prefix "/content/gallery" for images as a prefix. For example, the picture "D:\Projekte\test_images\test1.jpg" would be imported to "/content/gallery/Projekte/test_images/test1". I would like the image to be imported to "/content/gallery/imported_product_pictures/test1". Is there a way to do this without changing the source code?

Kind regards,
Sebastian

Jeroen Hoffman

unread,
Jul 11, 2014, 4:42:45 AM7/11/14
to hippo-c...@googlegroups.com
Hi,

I had a quick look but there seems to be no way to rename/remap binary folders
by configuration. You looking for something similar to the 'fileRenameMappings'
as present in applicationContext, correct?

Alternatives are to write some Java or to simply name your file system folder
like you want it in the repository.

HTH
Jeroen


On 09-07-14 9:34, Sebastian wrote:
> Hi there,
>
> I have another question.
>
> In the config file of my application (import-application.properties) I have the
> following configuration:
>
> ||
> import.repository.address =vm://
> import.repository.username =admin
> import.repository.password =admin
> import.signal.inbox =${catalina.base}/webapps/import-admin/WEB-INF/import-inbox
> import.signal.file.includes =import.start
> import.signal.direct.start =import.start
> import.data.base.path =file:///D:/Projekte/test_images
> import.data.binary.base.path =${import.data.base.path}
> import.repository.document.base.path =/content/gallery/imported_product_pictures
>
> So the images I would like to import are located under "D:\Projekte\test_images"
> and I would like to import them to "/conent/gallery/imported_product_pictures".
>
> With the above configuration the images are imported to
> "/content/gallery/Projekte/test_images".
>
> This is because of the following method that is part of the class BinaryFile:
>
> ||
> privateStringcreateFullPath(){
> Stringpath =FileUtils.getAbsolutePath(file);
> path =path.replace(config.getBinaryStripPath(),"");// TOLATER: method for
> stripping different from above.
>
> // on Windows the path will have backslashes which are not JCR path
> // separators
> path =path.replaceAll("\\\\","/");
>
> if(imageType){
> returnFileUtils.getFileFolder(IMAGE_PREFIX +StringUtils.removeStart(path,"/"),path);
> }
> returnFileUtils.getFileFolder(ASSET_PREFIX +StringUtils.removeStart(path,"/"),path);
> }
>
> The method takes the absoulte path, cuts the drive key and adds the prefix
> "/content/gallery" for images as a prefix. For example, the picture
> "D:\Projekte\test_images\test1.jpg" would be imported to
> "/content/gallery/Projekte/test_images/test1". I would like the image to be
> imported to "/content/gallery/imported_product_pictures/test1". Is there a way
> to do this without changing the source code?
>
> Kind regards,
> Sebastian
>
> --
> Hippo Community Group: The place for all discussions and announcements about
> Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google Groups "Hippo
> Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.

Sebastian

unread,
Jul 15, 2014, 3:45:31 AM7/15/14
to hippo-c...@googlegroups.com
Hey Jeroen,

the fileRenameMappings sound promising. I will have a look into it. Thanks for your help, I think I will get it to work somehow now :-).

Kind regards,
Sebastian

Sebastian

unread,
Apr 27, 2015, 10:00:08 AM4/27/15
to hippo-c...@googlegroups.com
Hi,

it's me again. We now have another issue:

Is it possible to determine if the import has finished? We need this for our build system so we can run further steps after the import has finished. It seems like the files in the ".done" folder don't indicate if all files are processed, instead it seems to indicated that the import started.

Kind regards,
Sebastian Kruwinnus

Woonsan Ko

unread,
Apr 27, 2015, 10:35:44 AM4/27/15
to hippo-c...@googlegroups.com
Hi Sebastian,

The camel routes configuration in routes.xml, the import application
executor runs asynchronously (#executeAsync) in a new thread. That's why
the camel route execution was done right away and so the done file is
created right away without waiting for the import process to finish:

<endpoint id="fileInbox"
uri="file://${import.signal.inbox}?filter=#singnalFileFilter&amp;preMove=inprogress&amp;move=.done"/>
<!-- snip -->
<route>
<from uri="ref:fileInbox" />
<to uri="direct:execute-import-application" />
</route>
<!-- snip -->
<route>
<from uri="direct:execute-import-application" />
<to uri="bean:importApplicationExecutor?method=executeAsync" />
</route>

I have not tested it by myself, but theoretically, if your
hippo-repository module dependency is 2.24.00 or later, and if you
change '?method=executeAsync' to '?method=execute', then maybe it can
wait for 'direct:execute-import-application' to finish its job and touch
the .done file afterward.
It might be worth trying it. ;-)

Regards,

Woonsan
> --
> Hippo Community Group: The place for all discussions and announcements
> about Hippo CMS (and HST, repository etc. etc.)
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google
> Groups "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hippo-communi...@googlegroups.com
> <mailto:hippo-communi...@googlegroups.com>.
--
w....@onehippo.com www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466

Sebastian

unread,
Apr 28, 2015, 4:13:59 AM4/28/15
to hippo-c...@googlegroups.com
Hi Woonsan,

your suggestion worked like a charm. Thank you a lot.

Kind regards,
Sebastian
Reply all
Reply to author
Forward
0 new messages