how to show metadata associate with a custom document - metadata

I would like to view the custom metadata that I associated with the my custom document, that I created with the document library, anyone know how to due with velocity variable?
Thanks in advance
Sabrina

You can get some meta-data articles properties with
$reserved-article-id.data
$reserved-article-title.data
full list you can find here
Also you can check this post, it has example how to get journal's categories at velocity template.
UPD. For getting document metadata you can use smth like this:
#set($dlFileUtil = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryLocalService"))
#set ($groupId = $getterUtil.getLong($groupId))
#set($fileEntry = $dlFileEntryUtil.getFileEntryByUuidAndGroupId($uuid,$longGroupId))
#set($metadataUtil=$serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryMetadataLocalService"))
You can use getFileEntryMetadata(ddmStructureId, fileVersionId) from $metadataUtil
More detailed code you can check this.
BR,
Paul Butenko

Related

How to fetch the RecordTypeName Dynamically from the schema

Can anyone share the solution that 'How to fetch the RecordTypeName Dynamically from the schema' to store into custom object.
You can use below syntax to fetch RecordTypeName dynamically from schema by giving custom ObjectName from which you want to fetch the recordTypeNames.
Further you can save this recordTypeNames in a custom field of your custom object.
Schema.DescribeSObjectResult objDesc = ObjectName.SObjectType.getDescribe();
List<Schema.RecordTypeInfo> objRTList = objDesc.getRecordTypeInfos();
for(Schema.RecordTypeInfo recType : objRTList) {
system.debug(recType.getName());
}
If you find it helpful, Please mark it as best answer.
Thanks

How to convert List<Objects> to an ObservableRangeCollection

I am using Xamarin Forms and their templates come with MvvMHelpers object to be used in the ViewModel as ObservableRangeCollections. I know ObservableCollections. If you try to do :
ObservableRangeCollection<Object> collection = new ObservableRangeCollection<Object>();
List<Object> objects = new List<Objects>();
collection.ReplaceRange(objects);
//error invalid type
Does anyone know how to use an ObservableRangeCollection? There is nothing on it in Google, Bing or StackOverflow.
Try the search you'll see Xamarin is promoting something so new that nobody knows what it is.
ObservableRangeCollection is a helper class by the Xamarin Evangelist James Montemagno.
The source is available in his github:
https://github.com/jamesmontemagno/mvvm-helpers
ObservableRangeCollection intends to help when adding/replacing Collections to a ObservableCollection.
In a "regular" ObservableCollection, for each new item added to the Collection, a OnCollectionChanged event would raise.
This is where ObservableRangeCollection gets in. It allows to replace/add elements to the Collection without firing an event for each element.
ObservableRangeCollection is subclassed from ObservableCollection.
So in your example, substitute your <T>, i.e:
ObservableRangeCollection<string> collection = new ObservableRangeCollection<string>();
List<string> objects = new List<string>();
collection.ReplaceRange(objects);
Consult the code here: https://github.com/jamesmontemagno/mvvm-helpers/blob/master/MvvmHelpers/ObservableRangeCollection.cs
This is not something that new. There's plenty of code using ObservableCollection.
What you are trying to achieve can be done like this:
List<Object> myList = new List<Objects>();
ObservableCollection<Object> myCollection = new ObservableCollection<Object>(myList);
Read more about ObservableCollection.
Check out my answer here, which is an enhanced version of ObservableRangeCollection optimized for less event raising and reuse of items in UI.

CQ5.5: getting Style of a target page

I've been working on this for sometime now, and I keep running into a wall. I think I'm close, but I figured someone out here in the land of SO might have some deeper insight if not a better way of doing what I'm trying to do.
Basically lets look at this scenario. I have a logo w/ some text that can be set from a few different places. If we look at the setup here is what it looks like.
Hiearchy:
Homepage [has designPath]
- Child Microsite Page [has designPath]
- Logo Component
Logic Flow (in logo component):
if properties.get("logoText") {
use this
} else if currentStyle.get("logoTextFromStyle") {
use this
} else if parentStyle.get("logoTextFromGlobal") {
use this
} else {
be blank
}
My query is with how to get the "parentStyle" of this page. Looking at the docs here: http://dev.day.com/docs/en/cq/5-5/javadoc/com/day/cq/wcm/api/designer/Style.html
I've been able to come up with the fact that I can get a Style object from the "designer" object made available via defineObjects. This is defined with the other utility objects like "pageManager, resourceUtil, resource, currentPage, etc".
With that being said this doesn't seem to work.
//assuming we have getting homePage earlier and it is a valid cq Page resource
Resource homePageResource.slingRequest.getResourceResolver().getResource(homePage.getPath());
Style homePageStyle = designer.getStyle(homePageResource);
at this point homePageStyle is null. To do some more testing I i tried passing currentPage.getPath() instead of homePage.getPath(). I assumed this would give me the currentPage resource and would in end yield the currentStyle object. This also resulted in a null Style object. From this I think I can safely conclude I'm passing the incorrect resource type.
I attempted to load the the cq:designPath into the resource hoping to get a Designer resourceType but to no avail.
I am curious if anyone has run into this problem before. I apologize if I've gone into too much detail, but I wanted to lay out the "why" to my question as well, just in case there was a better way overall of accomplishing this.
I've figured out how to return the style. Here is the rundown of what I did.
//get your page object
Page targetPage = pageManager.getPage("/path/to/target");
//get the Design object of the target page
Design homePageDesign = designer.getDesign(homePage);
//extract the style from the design using the design path
Style homePageStyle = homePageDesign.getStyle(homePageDesign.getPath());
it's very interesting the definition of "getStyle" is a little different from the designer.getStyle vs a Design.getStyle. designer.getStyle asks for a resource whereas Design.getStyle will take the path to a Design "cell" and return the appropriate Style.
I did some testing and it looks like it does work with inherited Styles/Designs. So if my cq:designPath is set at level 1 and I look up a page on at level 2 they will return the Design/Style at the cq:designPath set at level 1.
I hope this helps someone else down the way.
I tried this approach but was not getting the Styles in the Style object.
When we do this:
Design homePageDesign = designer.getDesign(homePage);
In this Design object we get the path till the project node i.e etc/design/myproject
After this if we try to extract the Style from the design path we do not get it.
However I implemented it in a different way.
In the design object, we also get the complete JSON of designs for(etc/design/myproject).
Get the sling:resourceType of the target page and get the value after last index of "/".
Check if this JSON contains the last value. If it contains, you can get your styles, i.e. image, etc.

how to get static block content custom attributes by block id in magento

I am creating this below block content in admin HTML. I cant able to get the slidertype attributes in 3columns.phtml but in template page i can get
$this->getData('slidertype').
So kindly give the solution that how to get the following attributes.
{{block type="catalog/product_bestseller" name="bestseller" slidercount="20" slidertype="1" template="catalog/product/bestseller_right.phtml"}}
I am using the below code to get static block attribute value. Its working fine for us.
$bestSellerBlock = Mage::getModel('cms/block')
->setStoreId(Mage::app()->getStore()->getId())
->load("best_seller");
$bestSellerContentText = strip_tags($bestSellerBlock->getContent());
preg_match('/slidertype="(.*?)"/u',$bestSellerContentText,$sliderTypeArray);
$sliderType = trim($sliderTypeArray[1]);
Thanks,
Arularasan D.

Get object in i18n form

Inside embedded i18n form i need to get object.
In this example i got ArtistImageTranslation object, but i need ArtistImage.
Can somebody help me, how to get this?
class ArtistImageTranslationForm extends BaseArtistImageTranslationForm
{
public function configure()
{
$this->getObject();
....
}
}
Have you tried the following?
$artistimage = $this->getObject()->getArtistImage();
I spent half of day today on the same problem and looks like I finally found something ;)
First, if you need to access the fields which are in the "Translation" part of the table you can access them directly from the Object contained in the form. Just access the properties without using the getter (I know it's not the nice way but it works). So you can use something like:
$this->getObject()->id;
$this->getObject()->translated_name;
etc.
If you really need the original object you can access it like this:
$this->getObject()->getTable()->getRelation('ArtistImage')
->fetchRelatedFor($this->getObject());
Hope this helps.
Try :
$artistimage = $this->getObject()->artistImage;
or
$artistimage = $this->getObject()->artist_image;