Remove unwanted attributes of Product - sap-commerce-cloud

i create Item Type Books with following attribute title,author,publishingAttribute,isAvailable
all are String except isAvailable this is boolean there is no extend the any class but when i run select from HAC it show extra attribute i want to remove this attribute i can how i can delete it.
This is my item type
[<itemtype generate="false" code="Books" autocreate="true">
<deployment table="Books" typecode="20000" />
<attributes>
<attribute qualifier="title" type="java.lang.String">
<description>Book Title</description>
<modifiers initial="true"/>
<persistence type="property"/>
</attribute>
<attribute qualifier="author" type="java.lang.String">
<description>>Book Author Name</description>
<persistence type="property"/>
</attribute>
<attribute qualifier="publishingAttribute" type="java.lang.String">
<description>>Book Author Attribute</description>
<persistence type="property"/>
</attribute>
<attribute qualifier="isAvailable" type="java.lang.Boolean">
<description>Available or not </description>
<persistence type="property"/>enter image description here
</attribute>
</attributes>
</itemtype>][1]

Look at the following itemtype definitions available in core-items.xml:
<itemtype code="Item"
extends=""
jaloclass="de.hybris.platform.jalo.Item"
deployment="de.hybris.platform.persistence.Item"
autocreate="true"
generate="false"
abstract="true">
<attributes>
<attribute autocreate="true" qualifier="creationtime" type="java.util.Date">
<persistence type="cmp" qualifier="creationTimestampInternal"/>
<modifiers read="true" write="false" search="true" optional="true" initial="true"/>
</attribute>
<attribute autocreate="true" qualifier="modifiedtime" type="java.util.Date">
<persistence type="cmp" qualifier="modifiedTimestampInternal"/>
<modifiers read="true" write="true" search="true" optional="true"/>
</attribute>
<attribute autocreate="true" qualifier="itemtype" type="ComposedType">
<persistence type="cmp" qualifier="typePkString"/>
<modifiers read="true" write="true" search="true" optional="true"/>
</attribute>
<attribute autocreate="true" qualifier="owner" type="Item">
<persistence type="cmp" qualifier="ownerPkString"/>
<modifiers read="true" write="false" search="true" optional="true" private="false" initial="true"/>
</attribute>
<attribute autocreate="true" qualifier="pk" type="de.hybris.platform.core.PK">
<persistence type="cmp" qualifier="pkString"/>
<modifiers read="true" write="false" search="true" optional="false"/>
</attribute>
<attribute autocreate="true" qualifier="sealed" type="boolean">
<persistence type="property" qualifier="sealed"/>
<modifiers read="true" write="false" search="true" optional="true"/>
</attribute>
</attributes>
</itemtype>
<itemtype code="ExtensibleItem"
extends="Item"
jaloclass="de.hybris.platform.jalo.ExtensibleItem"
deployment="de.hybris.platform.persistence.ExtensibleItem"
autocreate="true"
generate="false" abstract="true">
</itemtype>
<itemtype code="LocalizableItem"
extends="ExtensibleItem"
jaloclass="de.hybris.platform.jalo.c2l.LocalizableItem"
deployment="de.hybris.platform.persistence.c2l.LocalizableItem"
autocreate="true"
generate="false" abstract="true">
</itemtype>
<itemtype code="GenericItem"
extends="LocalizableItem"
jaloclass="de.hybris.platform.jalo.GenericItem"
deployment="de.hybris.platform.persistence.GenericItem"
autocreate="true"
generate="false">
</itemtype
As you can see, GenericItem extends LocalizableItem, LocalizableItem extends ExtensibleItem, and ExtensibleItem extends Item i.e. GenericItem ▸ LocalizableItem ▸ ExtensibleItem ▸ Item. It means that GenericItem inherits 6 attributes, creationtime, modifiedtime, itemtype, owner, pk, and sealed from Item.
When you create an itemtype without extending another itemtype, it extends GenericItem by default and therefore you will see all these 6 inherited attributes (creationtime, modifiedtime, itemtype, owner, pk, and sealed) in that itemtype.
For example, the following Flexible Search query will return these 6 inherited attributes (creationtime, modifiedtime, itemtype, owner, pk, and sealed) along with the attributes you have declared in your itemtype definition:
SELECT * FROM {Books}

Related

Custom Product restrictions are not working on child components

I have created a custom product restriction for a component due to project specific visibility rules. This product restriction can be applied on ExampleListComponent, ExampleComponent and also can be used in homepage, product page or content pages as and when required. ExampleListComponent can have multiple ExampleComponent instances. When apply the restriction on ExampleListComponent(which is added directly on homepage content slot) it is working fine but when apply the same on ExampleComponent(child component) it is not working. Following are some code snippets
items.xml
<collectiontype code="ExampleCardList" elementtype="ExampleComponent" autocreate="true" generate="true" type="list" />
<itemtype code="ExampleComponent" extends="AbstractMediaContainerComponent" autocreate="true" generate="true" jaloclass="com.example.core.jalo.ExampleComponent">
<attributes>
<attribute qualifier="title" type="localized:java.lang.String">
<persistence type="property" />
</attribute>
<attribute qualifier="secondaryMedia" type="Media">
<modifiers read="true" write="true" search="true" unique="false" />
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
<itemtype code="ExampleListComponent" extends="SimpleCMSComponent" autocreate="true" generate="true" jaloclass="com.example.core.jalo.ExampleListComponent">
<attributes>
<attribute qualifier="cards" type="ExampleCardList">
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
<itemtype code="ExampleAvailabilityRestriction" jaloclass="com.example.core.jalo.restrictions.ExampleAvailabilityRestriction" extends="AbstractRestriction" autocreate="true" generate="true">
<attributes>
<attribute qualifier="product" type="ProductList">
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
ExampleAvailabilityRestrictionEvaluator.java
public class ExampleAvailabilityRestriction implements CMSRestrictionEvaluator<ExampleAvailabilityRestrictionModel> {
public boolean evaluate(ExampleAvailabilityRestrictionModel restrictionModel, RestrictionData restrictionData) {
List<ProductModel> products = restrictionModel.getProduct();
if (CollectionUtils.isEmpty(products)) {
return true;
}
for (ProductModel product : products) {
if (!availabilityService.isProductAvailable(product.getCode())) {
return false;
}
}
return true;
}
}
I verified the other OTB restriction and code looks ok. Is there any other configurations required to be able to apply the restriction on child components.
This article helped me to resolve the issue.
https://answers.sap.com/questions/13121879/time-restriction-not-working-on-cms-link-component.html
Added the following line in examplecardcomponent.jsp
<c:if test="${ycommerce:evaluateRestrictions(component)}">
</c:if>
also we can add this on the parent component jsp(examplecardlistcomponent.jsp) while iterating the child components
<c:forEach var="exampleCard" items="${exampleCards}" varStatus="loop">
<cms:component component="${exampleCard}" evaluateRestriction="true" />
</c:forEach>

How to set Default Value for a Map attribute of an item in Items.xml Hybris?

I need to initialize a maptyped attribute of a item with defaultvalues of map.
lets say that we have defined a maptype
<maptype code="dummyMap" argumenttype="java.lang.String" returntype="java.lang.String" autocreate="true" generate="false" />
and we have declared a itemtype as
<itemtype code="dummyItem" autocreate="true" ...>
<attributes>
<attribute qualifier="dummyAttribute" type="dummyMap">
<defaultvalue>???</defaultvalue> <<<<<========= How should we initialize ?????
</attribute>
</attributes>
</itemtype>
As an example in similar case for an enum type attribute we define the default Value as
<defaultvalue>em().getEnumerationValue("dummyEnum","dummyEnum_Value")</defaultvalue>
How do we apply the same for a Maptyped attribute. Please let me know on how to initiale the attribute with a map value.
With the latset version of Hybris, you can try passing a java.util.Collections.singletonMap e.g.
<defaultvalue>java.util.Collections.singletonMap("one", java.math.BigDecimal.ONE)</defaultvalue>
When I tested it with Hybris v1811 (as shown below),
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="items.xsd">
<maptypes>
<maptype code="DummyMap"
argumenttype="java.lang.String"
returntype="java.math.BigInteger"
autocreate="true"
generate="false"/>
</maptypes>
<itemtypes>
<itemtype code="DummyItem" autocreate="true">
<deployment table="DummyItem" typecode="30001" />
<attributes>
<attribute qualifier="uname" type="java.lang.String">
<modifiers read="true" write="true" search="true" initial="true" optional="false"/>
<defaultvalue>"Hello"</defaultvalue>
<persistence type="property"></persistence>
</attribute>
<attribute qualifier="dummyAttribute" type="DummyMap">
<modifiers read="true" write="true" search="true" initial="true" optional="false"/>
<defaultvalue>java.util.Collections.singletonMap("one", java.math.BigDecimal.ONE)</defaultvalue>
<persistence type="property"></persistence>
</attribute>
</attributes>
</itemtype>
</itemtypes>
</items>
the XML Representation of DummyItem in the backoffice showed:
<itemtype code="DummyItem" extends="GenericItem" jaloclass="org.training.jalo.DummyItem" generate="true" singleton="false" jaloonly="false" autocreate="true">
<deployment table="dummyitem" typecode="30001"/>
<attributes>
<attribute generate="true" autocreate="true" qualifier="dummyAttribute" type="DummyMap"><!-- could not export defaultvalue '{one=1}' -->
<persistence type="property" qualifier=""/>
<modifiers read="true" write="true" search="true" encrypted="false" optional="false" removable="true" initial="true" unique="false" private="false" partof="false"/>
</attribute>
<attribute generate="true" autocreate="true" qualifier="uname" type="java.lang.String">
<defaultvalue>
new java.lang.String( "Hello" )
</defaultvalue>
<persistence type="property" qualifier=""/>
<modifiers read="true" write="true" search="true" encrypted="false" optional="false" removable="true" initial="true" unique="false" private="false" partof="false"/>
</attribute>
</attributes>
</itemtype>
As you can see, it was able to pass new java.lang.String( "Hello" ) as the default value for the attribute, uname but for the attribute, dummyAttribute, it shows, <!-- could not export defaultvalue '{one=1}' -->.

How to declare attribute with EnumType

In my itemtype I need to declare attribut with EnumType. But it is giving an error like below
hybris\bin\platform\resources\ant\antmacros.xml:795:
java.lang.ClassCastException: de.hybris.bootstrap.typesystem.YEnumType
cannot be cast to de.hybris.bootstrap.typesystem.YCollectionType
here is how I declare
<attribute qualifier="aaa" type="EnumType" autocreate="true" generate="true">
<persistence qualifier="bbbl" type="property" />
<modifiers read="true" write="true" search="true" removable="true"
optional="true" />
<description>aaa</description>
</attribute>
How to skip that error?
Do you have the EnumType actually created in enumtypes section? Try something like this:
<enumtypes>
<enumtype code="MyEnumType" autocreate="true" generate="true" dynamic="false">
<value code="SOMETHING"/>
</enumtype>
</enumtypes>
<attribute qualifier="aaa" type="MyEnumType" autocreate="true" generate="true">
<persistence type="property" />
<modifiers read="true" write="true" search="true" removable="true"
optional="true" />
<description>aaa</description>
</attribute>
This is the correct way to do it. First define the enum type and after that use it as a normal type.

Control attribute values order in RelaxNG

Is it possible to control the order of the attribute values in Relax NG? which can be achieved using xs:assert in schema?
XML:
<body>
<h1 class="title">title</h1>
<h2 class="subtitle">subtitle</h2>
<p class="paragraph1">para text 1</p>
<p class="paragraph2">Para text 2</p>
<p class="paragraph3">Para text 2</p>
</body>
The class value should be in order, paragraph1 should always come first and paragraph2 should come after paragraph1. The assert I tried in schema:
<xs:assert test="p[1]/#class = 'paragraph1'
and ((every $i in p[2] satisfies $i/#class = 'paragraph2')
and (every $i in p[3] satisfies $i/#class = 'paragraph3')) "/>
A (compact-syntax) RelaxNG grammar to express what the question describes could be written as:
start = element body { h1?, h2?, p.paragraph1?, p.paragraph2?, p.paragraph3? }
h1 = element h1 { text & attribute class { string } }
h2 = element h2 { text & attribute class { string } }
p.paragraph1 = element p { text & attribute class { string "paragraph1" } }
p.paragraph2 = element p { text & attribute class { string "paragraph2" } }
p.paragraph3 = element p { text & attribute class { string "paragraph3" } }
Expressed in the RelaxNG XML syntax:
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="">
<start>
<element name="body">
<optional>
<ref name="h1"/>
</optional>
<optional>
<ref name="h2"/>
</optional>
<optional>
<ref name="p.paragraph1"/>
</optional>
<optional>
<ref name="p.paragraph2"/>
</optional>
<optional>
<ref name="p.paragraph3"/>
</optional>
</element>
</start>
<define name="h1">
<element name="h1">
<interleave>
<text/>
<attribute name="class">
<data type="string"/>
</attribute>
</interleave>
</element>
</define>
<define name="h2">
<element name="h2">
<interleave>
<text/>
<attribute name="class">
<data type="string"/>
</attribute>
</interleave>
</element>
</define>
<define name="p.paragraph1">
<element name="p">
<interleave>
<text/>
<attribute name="class">
<value type="string">paragraph1</value>
</attribute>
</interleave>
</element>
</define>
<define name="p.paragraph2">
<element name="p">
<interleave>
<text/>
<attribute name="class">
<value type="string">paragraph2</value>
</attribute>
</interleave>
</element>
</define>
<define name="p.paragraph3">
<element name="p">
<interleave>
<text/>
<attribute name="class">
<value type="string">paragraph3</value>
</attribute>
</interleave>
</element>
</define>
</grammar>

Maximo Anywhere Tasks for new work order

Not able to create tasks for new work order from Anywhere. Please suggest
Able to create a new work order without task
Added a new view for tasks, and trying to add taskId, status, Asset with lookup and Location with lookup.
lookup are not visible in UI. Here is my code
<view id="WorkExecution.NewAdhocWorkOrderInspTaskView" label="Create Inspection Tasks" >
<requiredResources id="WorkExecution.NewAdhocWorkOrderInspTaskView_requiredResources">
<requiredResource id="WorkExecutionAdhocINspTaskView.NewAdhocWorkOrderView_additionalasset" name="additionalasset"/>
</requiredResources>
<container id="WorkExecution.NewAdhocWorkOrderInspTaskView_workOrder_container_0" resource="AdhocWOInspTaskResource" >
<group id="WorkExecution.NewAdhocWorkOrderInspTaskView_group_0">
<groupitem id="WorkExecution.NewAdhocWorkOrderInspTaskView_workOrder_groupitem_4" >
<text editable="true" id="WorkExecution.NewAdhocWorkOrderView_groupitem_WorkExecution0.Asset" label="Asset2" layoutInsertAt="item1"
lookup="WorkExecutionAdhocWOInsptask" lookupAttribute="assetnum" placeHolder="Tap to enter1" resourceAttribute="InspTaskAssetNum" />
</groupitem>
</group>
</container>
</view>
<resource additionalData="true" id="AdhocWO_InsptaskResource" name="AdhocWOInspTaskResource" describedBy="http://jazz.net/ns/ism/asset/smarter_physical_infrastructure#WoActivity" providedBy="/oslc/sp/SmarterPhysicalInfrastructure" >
<attributes id="AdhocWO_InsptaskResource_attributes">
<attribute describedByProperty="spi:taskid" id="AdhocWO_InsptaskResource_spi_taskid" name="InspTaskId"/>
<attribute describedByProperty="spi:assetnum" id="AdhocWO_InsptaskResource_spi_AssetNum" name="InspTaskAssetNum"/>
<attribute describedByProperty="spi:location" id="AdhocWO_InsptaskResource_spi_Location" name="InspTaskLocation"/>
<attribute describedByProperty="spi:status" id="AdhocWO_InsptaskResource_spi_Status" name="InspTaskStatus"/>
</attributes>
</resource>
<resource additionalData="true" describedBy="http://open-services.net/ns/asset#Asset" id="additionalasset" name="additionalasset" pageSize="1000" providedBy="/oslc/sp/AssetManagement">
<attributes id="additionalasset_attributes">
<attribute describedByProperty="dcterms:identifier" id="additionalasset_assetuid_dctermsidentifier" name="assetuid"/>
<attribute describedByProperty="spi:assetid" id="additionalasset_assetid_spiassetid" name="assetid"/>
<attribute describedByProperty="spi:orgid" id="additionalasset_orgid_spiorgid" index="true" name="orgid"/>
<attribute describedByProperty="spi:siteid" id="additionalasset_siteid_spisiteid" index="true" isExactMatchIndex="true" name="siteid"/>
<attribute describedByProperty="oslc:shortTitle" id="additionalasset_assetnum_oslcshortTitle" index="true" name="assetnum"/>
</attributes>
<queryBases id="additionalasset_queryBases">
<queryBase id="additionalasset_queryBase_getadditionalasset" name="getadditionalasset" queryUri="/oslc/os/oslcasset"/>
</queryBases>
<whereClause id="additionalasset_whereClause"/>
</resource>
<lookup id="WorkExecutionAdhocWOInsptask" label="Select Asset" resource="additionalasset">
<requiredResources id="WorkExecutionAdhocWO_Insptask.AssetLookup_requiredResources">
<requiredResource id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset" name="additionalasset"/>
<requiredResource id="WorkExecutionAdhocWO_Insptask.AssetLookup_workOrder" name="AdhocWOInspTaskResource"/>
</requiredResources>
<list id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_list" resource="additionalasset">
<listItemTemplate id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_listItemTemplate_Item2Desc2" layout="Item2Desc2">
<listtext cssClass="bold textappearance-medium" id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_Item2Desc2_assetnum" layoutInsertAt="item1" resourceAttribute="assetnum"/>
<listtext cssClass="bold textappearance-medium" id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_Item2Desc2_description" layoutInsertAt="desc1" resourceAttribute="description"/>
<listtext id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_Item2Desc2_location" layoutInsertAt="item2" resourceAttribute="location"/>
<listtext id="WorkExecutionAdhocWO_Insptask.AssetLookup_additionalasset_Item2Desc2_locationdesc" layoutInsertAt="desc2" resourceAttribute="locationdesc"/>
</listItemTemplate>
</list>
<returnAttributes id="WorkExecutionAdhocWO_Insptask.AssetLookup_returnAttributes">
<returnAttribute id="WorkExecutionAdhocWO_Insptask.AssetLookup_assetnum_asset" sourceAttribute="assetnum" targetAttribute="InspTaskAssetNum" />
</returnAttributes>
</lookup>

Resources