Get Episerver Property though Episerver API/Database query - database

I have an episerver site with almost all the blocks having a common Image property as given below:
[Display(GroupName = SystemTabNames.Content, Name = "Image", Description = "This is description link for alt", Order = 30)]
[UIHint(UIHint.Image)]
public virtual ContentReference Image { get; set; }
This property is used throughout the application. I need to generate a report to get all the references where the Description is empty.
Is there a way to get the above using episerver api or database query?
This is a new area for me & so any input would be appreciated.

Related

How to index general link field

I would like to know how Solr indexes general link field or do we need to create computed index field for this ?
I have a helper class which is inheriting from SearchResultItem and it has below index field.
[IndexField("Call To Action")]
public LinkField CallToAction { get; set; }
This field is a general link field in sitecore.
Below is the search code which retrieves all the Event_card values except CallToAction (i.e. Always null). if I convert the field type from Link to string , I get the entire general link raw value which is difficult to parse at view and make it editable through glass mapper.
if (result.TotalSearchResults != 0)
{
//Load Event card data to be displayed on page
var resultItems =
result.Select(c => new Event_Card
{
Headline = c.Document.Headline,
Start_Date=c.Document.StartDate,
Content=c.Document.ContentData,
Call_To_Action=c.Document.CallToAction // this is always null
});
}
Here is my Entity class related to Event_Card
Event_Card
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
[SitecoreField(IEvent_CardConstants.Call_To_ActionFieldName)]
public virtual Link Call_To_Action { get; set; }
IEvent_Card
[SitecoreField(IEvent_CardConstants.Call_To_ActionFieldName)]
Link Call_To_Action { get; set; }
public static partial class IEvent_CardConstants
{
public static readonly ID Call_To_ActionFieldId = new ID("4c296a05-d05f-47c5-8934-8801bec5be85");
public const string Call_To_ActionFieldName = "Call To Action";
}
Can anybody let me know How can I achieve this. If we need to use computed field , an example would be of great help.
Thanks in Advance !
I just quickly browsed and found useful link for you.
Map sitecore 8 general link field from Index
I think this Stack overflow question describes what you are saying and there is a link which might be helpful to you.

Solrnet can't get mapping to work

I am using VS2012, .NET 4.5 and SolrNet. I am struggling with solrnet mappings. I've succesfully started Apache Solr with jetty on http://localhost:8983/solr. My class which I want to add to solr is:
public class Register
{
[SolrUniqueKey("id")]
public string Id { get; set; }
[SolrField("body")]
public string Body { get; set; }
}
I succesfully connect to solr, but I can't put my document into it:
Startup.Init<Register>(solrAddress);
Solr = ServiceLocator.Current.GetInstance<ISolrOperations<Register>>();
var reg = new Register
{
Id = "SP2514N",
Body = #"Dosel je prosel"
};
Solr.Add(reg);
Solr.Commit();
Here I receive error, that 'body' is unknown field. I've also used MappingManager, like this:
var mgr = new MappingManager();
var property = typeof(Register).GetProperty("Id");
mgr.Add(property, "id");
mgr.SetUniqueKey(property);
mgr.Add(typeof(Register).GetProperty("Body"), "body");
But, again, my field was not mapped. What am I doing wrong? Isn't the mapping to solr supposed to be done through code? Do I need a special xml file?
You need to confirm that you have a body field defined in your schema. If you are just using the default schema that comes with Solr, it does not include a body field. You can copy an existing similar entry in the schema.xml file, like description to get you going.
For more reference on configuring the Solr schema please refer to the following:
Solr Reference Guide - Overview of Documents, Fields and Schema Design
schema.xml - SolrTutorial.com

Create an attribute programatically in EPiServer

This may be a very simple question but I'm very new to EPiServer, so pls help.
I'm working on the EPiServer Relate demo site. I want to progrmatically create a new attribute on Episerver.Common.Security.IUser type. I have created attributes using CMS edit mode Admin options. But I want to know how to do this in code.
You may want to use CommunityAttributeBuilder (https://github.com/Geta/Community.EntityAttributeBuilder) that is similar to PageTypeBuilder for CMS. Currently it's supporting CMS6, I'll commit v7 as soon I will finish testing.
By decorating your class properties with special attribute you will find those created in target site.
For instance:
[CommunityEntity(TargetType = typeof(IUser))]
public class UserAttributes : IClubUserAttributes
{
[CommunityEntityMetadata]
public virtual int AccessType { get; set; }
[CommunityEntityMetadata]
public virtual string Code { get; set; }
[CommunityEntityMetadata]
public virtual int EmployeeKey { get; set; }
[CommunityEntityMetadata]
public virtual bool IsAdmin { get; set; }
}
Library will scan all assemblies and look for types decorated with CommunityEntity attribute, if found one then properties will be scanned and those decorated with CommunityEntityMetadata attribute will be automatically created in DB.
It also supports strongly-typed interface over IUser type:
var metadata = user.AsAttributeExtendable<UserAttributes>();
metadata.AccessType = info.AccessType;
metadata.Code = info.Code;
metadata.EmployeeKey = info.EmployeeKey;
metadata.IsAdmin = info.IsAdmin;
More info about library could be found - http://world.episerver.com/Blogs/Valdis-Iljuconoks/Dates/2012/6/Community-Attribute-Builder-final/
More info about internals (if interested) could be found here - http://www.tech-fellow.lv/2012/06/when-you-need-something-stronger/
You need to use the AttributeHandler class.
Joel has written a great guide with example code here

Episerver LinkItemCollection not visible to users

We are using PageTypeBuilder to define our PageTypes, on one page we have a property which represents a Link item collection as below:
[PageTypeProperty(Type = typeof(PropertyLinkCollection), HelpText = "Test links.", EditCaption = "Test links", SortOrder = 11)]
public virtual LinkItemCollection PageLinks { get; set; }
We can populate this in CMS editor mode with links, save and publish without any errors. We then have a user control that inherits from EPiServer.UserControlBase and grabs the LinkItemCollection property using the below code and binds it to a repeater:
var links = currentPage.Property["PageLinks"].Value as LinkItemCollection;
if (links != null)
{
linkRepeater.DataSource = links;
linkRepeater.DataBind();
}
If I view the page when logged in as a CMS editor this page works fine and the links parameter is populated correctly, however if I view the page as a normal user and not logged in the links variable is always null (although when I'm debugging I can see the currentPage.Property["PageLinks"] is present, and the type is LinkCollection, its just that the Value is null
Is there something I need to configure here, permissions on a specific page type?
The problem is most likely one of the pages in the LinkItemCollection not being accessible by outside visitors. Try accessing the links in the collection as an outside visitor and remove any of the links that are in fact locked from outside view.

What is the SOQL to get all Public Calendars, in a Salesforce instance?

Does anyone know how to perform a query to get all public calendars? You can see the list by going to Setup ... Customize ... Activities .. Public Calendars and Resources
What are these calendar objects?
My goal is to find a way to show these calendars in a VisualForce page to make it easier for users to find them.
If you run a .getSobjectType() on the ID it comes up as a calendar object. When you try and query that object it says it's not available. It looks like the custom setting is the only route for now.
As near as I can tell, Salesforce hasn't directly exposed the Public Calendar object for customers to query directly.
Public Calendars seem to fall into the 023 namespace, which is a standard object, but I can't find any object in the Schema that have that namespace, which leads me to believe that SFDC has hidden them from us.
If you want to show the list in Visualforce, you could use a workaround using the PageReference GetContent() method on the Calendar page and then fetch the details from the html.
Note that this won't work in APEX triggers..
Public Class CalendarResource{
public Id crId {get;set;}
public String label {get;set;}
public String type {get;set;}
}
Pagereference r = new PageReference('/_ui/common/data/LookupResultsFrame?lkfm=swt&lknm=cal&lktp=023&cltp=resource&lksrch=#');
String html = r.getContent().toString();
List<CalendarResource> cals = new List<CalendarResource>();
Matcher m = Pattern.compile('lookupPick\\(\'swt\',\'cal_lkid\',\'cal\',\'\',\'(.*?)\',\'(.*?)\',\'\',\'\'\\)">(.*?)</a></TH><td class=" dataCell ">(.*?)<\\/td><\\/tr>').matcher(html);
//While there are labels
while (m.find()) {
//system.debug(m.group(3));
//system.debug(m.group(4));
CalendarResource cr = new CalendarResource();
cr.crId = m.group(1);
cr.label = m.group(2);
cr.type = m.group(4);
cals.add(cr);
}
for(CalendarResource cr : cals){
system.debug(cr.crId+'__'+cr.label+'___'+cr.type);
}
You can do this in the current API version by: "SELECT Id,Name FROM Calendar where Type='Resource'

Resources