I am a beginner in the Sap Hybris. I created a new model BookComponent from SimpleCMSComponent
<itemtypes>
<itemtype code="BookComponent" extends="SimpleCMSComponent" generate="true" autocreate="true"
jaloclass="com.training.core.jalo.BookComponent">
<description>Used to display offers on homepage</description>
<attributes>
<attribute type="localized:java.lang.String" qualifier="headrerText">
<modifiers read="true" write="true" optional="true" />
<persistence type="property" />
</attribute>
<attribute type="localized:java.lang.String" qualifier="footerText">
<modifiers read="true" write="true" optional="true" />
<persistence type="property" />
</attribute>
<attribute type="Media" qualifier="bookImage">
<modifiers read="true" write="true" optional="false" />
<persistence type="property" />
</attribute>
<attribute type="BookLinksList" qualifier="bookImageLink">
<persistence type="property" />
<description>List of CMS Link Component</description>
<modifiers read="true" write="true" />
</attribute>
</attributes>
</itemtype>
</itemtypes>
<collectiontypes>
<collectiontype code="BookLinksList"
elementtype="CMSLinkComponent"
autocreate="true" generate="true" type="list" />
</collectiontypes>
after ant all with success and update, my model is created correctly even in the database with all the attributes as we defined in trainingcore-items.xml file.
Then I created some impex to insert my new component as following :
$contentCatalog=apparel-ukContentCatalog
$contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Staged])[default=$contentCatalog:Staged]
$productCatalog=apparelProductCatalog
$productCatalogName=Apparel Product Catalog
$productCV=catalogVersion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
$picture=media(code, $contentCV) ;
$siteResource=jar:de.hybris.platform.apparelstore.constants.ApparelstoreConstants&/apparelstore/import/sampledata/contentCatalogs/$contentCatalog
$jarResourceCms=jar:de.hybris.platform.apparelstore.constants.ApparelstoreConstants&/apparelstore/import/sampledata/cockpits/cmscockpit
$category=category(code, $productCV)
$lang=en
INSERT_UPDATE CMSLinkComponent ; $contentCV[unique=true] ; uid[unique=true] ; name ; url ; &linkRef ; &componentRef ; target(code)[default='sameWindow'] ; $category
; ; InformatiqueBookLink ; Informatique Book Link ; /InformatiqueBookLink ; InformatiqueBookLink ; InformatiqueBookLink ; ;
; ; ScienceBookLink ; Science Book Link ; /ScienceBookLink ; ScienceBookLink ; ScienceBookLink ; ;
; ; AstroBookLink ; Astro Book Link ; /AstroBookLink ; AstroBookLink ; AstroBookLink ; ;
INSERT_UPDATE Media ; $contentCV[unique=true] ; code[unique=true] ; #media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator] ; mime[default='image/jpeg'] ; &imageRef ; folder(qualifier)[default='images'] ; altText
; ; bookMedia ; $siteResource/images/banners/homepage/books.jpeg ; ; books.jpeg ; ; books.jpeg ;
INSERT_UPDATE BookComponent ; $contentCV[unique=true] ; uid[unique=true] ; name ; headrerText[lang=$lang] ; footerText[lang=$lang] ; bookImage(code) ; &componentRef ; bookImageLink(&linkRef)
; ; bookofferComponent ; offer Component ; "Header text" ; "Footer text" ; bookMedia ; bookofferComponent ; InformatiqueBookLink,ScienceBookLink,AstroBookLink
but insertion does not pass and on the hac cosnole this message is displayed
NSERT_UPDATE BookComponent;catalogVersion(CatalogVersion.catalog(Catalog.id[default=apparel-ukContentCatalog]),CatalogVersion.version[default=Staged])[default=apparel-ukContentCatalog:Staged][unique=true];uid[unique=true];name;headrerText[lang=en];footerText[lang=en];bookImage(code);&componentRef;bookImageLink(&linkRef)
,,,,Exception : line 29: cannot create BookComponent with values ItemAttributeMap[ registry: null, type: <null>, data: {bookimagelink=[8796256896060, 8796256928828, 8796256961596], uid=bookofferComponent, bookimage=bookMedia(bookMedia(8798226972702)), catalogversion=apparel-ukContentCatalog/Staged(8796093186649), headrertext={8796093055008->en=Header text}, name=offer Component, footertext={8796093055008->en=Footer text}} ] due to [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator#113d6726]:valeurs manquantes pour [footerText, headrerText] dans le modèle BookComponentModel (<unsaved>) pour créer un nouveau BookComponent, Exception : line 3: cannot create BookComponent with values ItemAttributeMap[ registry: null, type: <null>, data: {bookimagelink=[8796256896060, 8796256928828, 8796256961596], uid=bookofferComponent, bookimage=bookMedia(bookMedia(8798226972702)), catalogversion=apparel-ukContentCatalog/Staged(8796093186649), headrertext={8796093055008->en=Header text}, name=offer Component, footertext={8796093055008->en=Footer text}} ] due to [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator#113d6726]:valeurs manquantes pour [footerText, headrerText] dans le modèle BookComponentModel (<unsaved>) pour créer un nouveau BookComponent;;bookofferComponent;offer Component;Header text;Footer text;bookMedia;bookofferComponent;InformatiqueBookLink,ScienceBookLink,AstroBookLink
However I add all mandatory fields.
Thank for you all in advance.
It may be problem with quotes in "Footer text". Try to remove them or escape or replace with single quotes 'Footer text' or with double double quotes ""Footer text"".
You need to reference medias by code AND catalog version. When you only reference it by code, it will only pass if there is only one media with that specific code in your database. Once you synchronize the apparel-ukContentCatalog there will be two medias with the code "bookMedia" in your database. One in the Staged and one in the Online catalog version. So use:
bookImage(code,$contentCV)
Related
I am trying to find any nodes in a xml whos tags start with a certain pattern.
<data>
<general>
<va value="400" /> <!--looking for this "v-tag"-->
<vb value="42" /> <!-- and this one-->
<y value="43" />
</general>
<special>
<va value="100" />
</special>
</data>
I cannot put together the xpath expression. Something like this
xyz = lxml.etree.parse( ... )
vees = xyz.xpath("general/[tag='v*']")
I would like to have vees beeing
vees
Out[64]: [<Element va at 0x....>, <Element vb at 0x...>]
Try changing:
vees = xyz.xpath("general/[tag='v*']")
to
doc.xpath('//general//*[starts-with(name(),"v")]')
and see if it works.
itemtype code="CartPageConfig" jaloclass="de.hybris.platform.jalo.config.CartPageConfig">
<deployment table="CartPageConfig" typecode="21033" />
<attributes>
<attribute qualifier="code" type="java.lang.String">
<modifiers unique="true" optional="false"/>
<persistence type="property" />
</attribute>
<attribute qualifier="shipToStores" type="AllowedStoresList">
<description> List of stores where the notification should be shown </description>
<persistence type="property"/>
</attribute>
</attributes>
<indexes>
<index name="code" unique="true">
<key attribute="code"/>
</index>
</indexes>
</itemtype>
And the following item to insert data for the above item:
CartPageConfig;code[unique=true];shipToStores;baseStores(uid)
;cartPageConfig;US;en-US-PT02
I get the following error when trying to import the above impex:
CartPageConfig,,,,;code[unique=true];shipToStores;# no current header for value line
,,,,;cartPageConfig;US;# no current header for value line
23.07.2019 16:12:06: ERROR: de.hybris.platform.impex.jalo.ImpExException: Can not resolve any more lines ... Aborting further passes (at pass 2). Finally could not import 2 lines![HY-123]
Try :
INSERT_UPDATE CartPageConfig;code[unique=true];shipToStores;baseStores(uid)
;cartPageConfig;US;en-US-PT02
I have a question relating to the Liferay Service Builder. I want to create a many-to-many relationship with custom colums in the created Join table.
This is my service.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<service-builder package-path="de.mycompany.mm.services">
<author>rawdog</author>
<namespace>mycompany</namespace>
<entity name="Registration" local-service="true" remote-service="false">
<column name="RegID" type="long" primary="true"></column>
<column name="Email" type="String"></column>
<column name="Hash" type="String"></column>
<column name="Validate" type="boolean"></column>
<column name="NewsletterID" type="Collection" entity="Newsletter" mapping-table="Registration_Newsletter"/>
<finder name="Hash" return-type="Registration">
<finder-column name="Hash"></finder-column>
</finder>
</entity>
<entity name="Newsletter" local-service="true" remote-service="false">
<column name="NewsletterID" type="long" primary="true"></column>
<column name="Name" type="String"></column>
<column name="Status" type="boolean"></column>
<column name="RegID" type="Collection" entity="Registration" mapping-table="Registration_Newsletter"/>
</entity>
</service-builder>
This automatically creates following SQL CREATE statement:
create table mycompany_Registration_Newsletter (
RegID LONG not null,
NewsletterID LONG not null,
primary key (ANID, MMID)
);
How could I also automatically create custom colums in the JOIN table like Status BOOLEAN. It should look like this in the end:
create table mycompany_Registration_Newsletter (
RegID LONG not null,
NewsletterID LONG not null,
Status BOOLEAN,
primary key (ANID, MMID)
);
Thanks for any help.
You have two ways to solve this problem :
You can manually modify your joined table by adding your boolean column (execute sql script on your database : ALTER TABLE yourJoinedTable ADD yourBooleanColumn BOOLEAN NOT NULL;) and then define CUSTOM SQL / NATIVE QUERY IN SERVICE BUILDER to use this joined table.
(If you want Service Builder to handle this joined table as others tables) to define it as an entity in your service.xml so that you'll be able to use it easily once you had defined 2 OneToMany relationship "right side" and "left side" of your joined table (assuming that a ManyToMany = is "equal" to = oneToMany left side && ManyToOne right side).
I'm a newbe in ActivePivot and i want to create a dimension with DimensionType = time, where the dates a shown in hierachical manner. E.g. for 30.01.2013 i need one level for the year -> 2013 (sort descending), one level for the month (also sort descending) -> 1 and one level for the days (also sort descending) -> 30, 29, 28, ...
Viewed via ActivePivotLive should look like:
- 2013
- 1
- 30
- 29
- 28
- ...
+ 2012
+ 2011
and so on.
I went through the ActivePivot sandbox project, but i didn't find anything that helps me. The TimeBucket dimension which i've found in the EquityDerivativesCube makes something similar but the buckets are created in a different manner.
How can i solve this problem?
Ok, i handle it out.
It is not necessary to make the round trip and to implement a dimension. It is easy done by levels and the a calculator.
Here the code from the EquityDerivativesCube.xml
<!-- Standard time buckets, bucketing performed at insertion -->
<dimension name="TimeBucket">
<properties>
<entry key="DimensionType" value="time" />
<entry key="IsAllMembersEnabled" value="true" />
</properties>
<level name="Year">
<properties>
<entry key="LevelType" value="TIME_YEARS" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<properties>
<entry key="LevelType" value="TIME_MONTHS" />
</properties>
<comparator pluginKey="Custom">
<order name="firstObjects">
<value>Jan</value>
<value>Feb</value>
<value>Mrz</value>
<value>Apr</value>
<value>Mai</value>
<value>Jun</value>
<value>Jul</value>
<value>Aug</value>
<value>Sep</value>
<value>Okt</value>
<value>Nov</value>
<value>Dez</value>
</order>
</comparator>
</level>
<!-- The Value Date level is the field Date -->
<level name="Value Date" property="Date">
<properties>
<entry key="LevelType" value="time" />
</properties>
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>
I added the following snippet to PNLCalculator.enrichTrade:
...
pnl = pnlVega + pnlDelta;
// Year and month calculations BEGIN
final Calendar cal = CALENDAR.get();
cal.setTime(trade.getDate());
final int year = cal.get(Calendar.YEAR);
final String month = DateFormatSymbols.getInstance(GERMANY).getShortMonths()[cal.get(MONTH)];
// Year and month calculations END
// instantiate the result that will hold the enrichment data
final PNLCalculatorResult result = new PNLCalculatorResult();
...
// add them to the result
result.setYear(year);
result.setMonth(month);
...
I also extended the SanboxFields.xml with the two new fields:
...
<field name="Year" type="integer" />
<field name="Month" type="string" />
...
Cheers!
The TimeBucket dimension in the ActivePivot Sandbox application defines a custom bucketing based on financial time periods. Creating a standard year > month > day hierarchy is actually simpler and seamless in ActivePivot. In the description if the schema you need to declare three fields (one for year, one for month and one for the day).
<field name="Year" indexation="dictionary" />
<field name="Month" indexation="dictionary" />
<field name="Day" indexation="dictionary" />
And then you need to declare a dimension that references those fields.
<dimension name="Time">
<level name="Year" />
<level name="Month" />
<level name="Day" />
</dimension>
Then ActivePivot will build the time hierarchy incrementally, by introspecting the loaded records.
This will work automagically if the input records (objects) already contain a Year attribute, a Month attribute and a Day atribute (For instance if the input records are POJOs with getYear(), getMonth() and getDay() methods). If that is not the case and that for instance the input records only have a date attribute, you can either transform your records before puutting them into ActivePivot, or inject a calculator in ActivePivot (com.quartetfs.biz.pivot.classification.ICalculator) that will on the fly compute the three fields from the date. Look at the ActivePivot Sandbox application for an example of calculator.
Extracting those fields is usually done with standard Java code:
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("Date: " + date);
System.out.println("Year: " + calendar.get(Calendar.YEAR));
System.out.println("Month: " + calendar.get(Calendar.MONTH) + 1);
System.out.println("Day: " + calendar.get(Calendar.DAY_OF_MONTH));
About the ordering of members in the level of a dimension, ActivePivot per default uses the natural ordering of java objects (those that implement java.lang.Comparable interface) so dates and integers will be sorted from the lowest to the greatest. You can easily reverse that by declaring a "ReverseOrder" comparator on the target level(s).
<dimension name="Time">
<level name="Year">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Month">
<comparator pluginKey="ReverseOrder" />
</level>
<level name="Day">
<comparator pluginKey="ReverseOrder" />
</level>
</dimension>
I am unable to run the code for moving file, when i use the ant macrodef attribute in groovy task inside the macrodef.
<macrodef name="dirmove">
<attribute name="todir" />
<attribute name="fromdir" />
<attribute name="includes" default="*" />
<sequential>
<var name="todir" value="#{todir}" />
<var name="fromdir" value="#{fromdir}" />
<var name="includes" value="#{includes}" />
<groovy>
File dir1 = new File(properties.'fromdir');
File dir2 = new File(properties.'todir');
def pattern = properties.get('includes')
println pattern;
dir1.eachFileMatch ~/pattern/, {
f->
boolean fileMoved = f.renameTo(new File(dir2, f.getName()));
//assert f.name == '1.txt' //**because File object is immutable, so I am just checking for the existing of previous file name. It is still there.
println fileMoved;
}
</groovy>
</sequential>
</macrodef>
This code correctly prints the value of pattern, which is coming from attribute value. But the eachFileMatch function doesn't picks up the spec
dir1.eachFileMatch ~/pattern/, {
should be
dir1.eachFileMatch ~/${pattern}/, {
As pattern is a String variable, so you need to add it in to the regex pattern as such.
Previously, you were just searching for all files called pattern