How to trigger a cronjob during initialization - sap-commerce-cloud

I want to trigger a cronjob which will delete some index and recreate it on initialization as a one time activity i.e cronjob should run only once.
How to achieve it?

Firstly you can create index with items.xml like below. This OOTB future auto create index on initialization or update.
<itemtype code="myType" autocreate="true" generate="true">
<attributes>
...
</attributes>
<indexes>
<index name="myIndex" unique="true">
<key attribute="myField1" />
<key attribute="myField2" />
</index>
</indexes>
</itemtype>
You can cover this scenario but you will lose database independency. You can connect to db directly with jdbc using spring beans and drop index with DDL command. You can check below groovy script for this.
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
def config = spring.getBean("configurationService").getConfiguration();
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(config.getString("db.driver"));
dataSource.setUrl(config.getString("db.url"));
dataSource.setUsername(config.getString("db.username"));
dataSource.setPassword(config.getString("db.password"));
JdbcTemplate jdbc = new JdbcTemplate(dataSource)
jdbc.execute("ALTER TABLE MYTABLE ALTER (P_MYFIELD BIGINT)");
For creating index at initialization step you need to extend AbstractSystemSetup class. If you can add your index with items.xml, you will not need to extend this class.

Related

Redefining data type in items.xml in Hybris

I had a datatype defined as follows in items.xml:
<attribute qualifier="daysOfWeek" type="java.lang.String">
<persistence type="property" />
</attribute>
To modify the data type to enumeration,I redefined it as follows:
<enumtype code="DaysOfWeek" autocreate="true" generate="true">
<value code="Monday" />
<value code="Tuesday" />
</enumtype>
<attribute qualifier="daysOfWeek" type="DaysOfWeek">
<persistence type="property" />
</attribute>
After updating the extension,I am getting SQLException.Is there anything wrong with this approach?
hybris doesn't support updates like this in a "running" system.
The reason is that hybris won't drop any db columns and recreate them as any data contained in there would be lost (plus its probably difficult to write this logic for multiple supported databases).
If you are in a development phase of your project, the easiest way to fix this is to initialize your system from scratch (i.e. it will drop the database and recreate it).
If you have a live system / production system, you would have to take another approach:
You would define a new attribute (different name!) with your enumeration type.
You would then probably update any code to use the new field.
You would also have to take care of data migration, i.e. write some scripts that transfer the old data (e.g. the String "Monday" to the new respective enum value).
Hope this helps!

Dynamics CRM 2013: Advanced Find FetchXML contains extra fields - why?

I have two (related) questions:
I am having a puzzling problem with the Advanced Find function. I set up the fields I require, both in the criteria and display section and then hit 'Download Fetchxml'. What I end up with is fields that I never asked for. For example, in my advanced find I asked for All Activities. I changed the results to show me only the Date Created, Activity Type, Subject and Regarding fields. The (truncated) generated fetchXML looks like this:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="activityid" />
<attribute name="instancetypecode" />
<attribute name="community" />
<attribute name="createdon" />
<attribute name="regardingobjectid" />
<order attribute="subject" descending="false" />
Why have those extra columns been included? I didn't ask for the 'community' attribute anywhere, for example.
Second question:
What determines the output order of the fields? I ran the above fetchXML through Fetch Tester 3000 (saved my life - thank you!) and the output table bears no relation to the order of the attributes in the xml. This is true also when I use the fetchXML elsewhere.
Thanks in advance for your comments
The FetchXML returned by the button Download Fetch XML is generated internally and in some scenarios it returns extra columns (as you found), for example the primary key field of the entity is always added.
If you remove the additional attributes the FetchXML is still valid and can be executed.
Regarding the order, the tool you used (Fetch Tester 3000) display the fields inside the Table View ordered by their logicalname, inside Dynamics CRM the order of the attributes (subgrids and advanced find results) is defined using another XML definition known as LayoutXML

how to redeclare core model attribute type without extending it in Hybris

By default Hybtis gives CreditCardType as a mandatory attribute. I want to make it Optional by using redeclare=true (without extending it with new model). I am wondering why its not updating CreditCardPaymentInfo model. I am doing like this
<itemtype code="CreditCardPaymentInfo" autocreate="false" generate="false" >
<attributes>
<attribute qualifier="type" type="CreditCardType" redeclare="true" autocreate="false" generate="true">
<modifiers read="true" write="true" search="true" optional="true" />
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
My ant build is working fine. But whenever i m updating running system, Hybris is not making this attribute non mandatory.
In case if I am extending it with my custom model and re-declaring it then its working, but that's what i don't need. I just want to make it optional without extending it.
I think its possible with Impex also, but i don't know the way. Please help.
You can't redeclare an attribute without extending a type.
The documentation for redeclare says it clearly:
Lets you re-define the attribute definition from an inherited type. In
essence, you can use a different type of attribute as well as
different modifier combinations than on the supertype.
Impex to the rescue. You can alter attribute modifiers with an impex afterwards.
Place following impex script
update AttributeDescriptor;enclosingType(code)[unique=true];qualifier[unique=true];optional
;CreditCardPaymentInfo;type;true
under <your-extension>/resources/impex/essentialdata-<chosse-a-name>.impex.
On each typesystem update (or initialize) this impex gets executed and marks CreditCardPaymentInfo.type as optional. For testing purpose, you can run this script within hac, too.

how to store the data into 2 tables in liferay service builder?

i have already created one portlet name is course-portlet. i have created the add.jsp for storing the course in to the database using service layer. now my requirement is i need to store the course details in two tables course,course_user. in course table column values are
cid,cname,sdate,sid. for this table i have created service builder. now my requirement is i have to create the another class in service layer which need to store the values in the table course_user cuid,cid,uid.is it possible with existing service layer? if possible how ? i have already created the methods addcourse() editcouse() and deletecourse() methods?
To add new entity using service builder
<entity name="Course_User" local-service="true"
remote-service="false">
<column name="cuid" type="long" primary="true"></column>
<column name="cid" type="Course" entity="Course" mapping-key="cid"></column>
<finder name="Cid" return-type="Collection">
<finder-column name="cid" />
</finder>
// finder method according to your need
</entity>
HTH

How to create xsd for an object

I have an method in which I need to pass parameters value some like this in the publish methods.
facebookclient. publish("me/events", FacebookType.class,Parameter.with("name", "Party"));
Instead of passing it as three parameters, I am trying to pass it as object storing these three parameters in the object record.
eg:
facebookclient.publish(record);
so that in publish method , I can get this
void publish(Record record)
{
String event= record.getEvent();
}
I am trying to create an xsd for these parameters. Kindly guide me how to do it. for me/events I can create an element in the xsd as
<element name="events" type="string" />
and refer it in an object
<element name="Record">
<complexType>
<sequence>
<element ref="fb:events" />
// how to specify for FacebookType.class,Parameter.with("name", "Party"))?
</sequence>
</complexType>
</element>
Kindly guide me, how to specify the element FacebookType.class,Parameter.with("name", "Party")) in xsd?
You can use the schemagen application (http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.wsfep.multiplatform.doc%2Finfo%2Fae%2Fae%2Ftwbs_jaxbjava2schema.html) to do it via command line or JAXB classes (http://jaxb.java.net/guide/Invoking_schemagen_programatically.html) programmatically... this is all assuming you have you classes annotated with the appropriate annotations.

Resources