int iPubId = Integer.parseInt(publicationId);
CriteriaFactory criteriaFactory = new CriteriaFactory();
PublicationCriteria pubCriteria = new PublicationCriteria(iPubId);
ItemTypeCriteria IsSchema = new ItemTypeCriteria(ItemTypes.SCHEMA);
Criteria allCriteria = criteriaFactory.And(pubCriteria,IsSchema);
Query myQuery = new Query();
myQuery.setCriteria(allCriteria);
SortParameter sortParameter = new SortParameter(SortParameter.ITEMS_TITLE,
SortParameter.ASCENDING);
myQuery.addSorting(sortParameter);
String[] itemResults = myQuery.executeQuery();
System.out.println("RERERERESULTS:"+itemResults.length);
-
Hello and welcome the Tridion Stack Exchange. Are you setup to actually publish schemas? You can filter to get certain component presentations based on a given schema, but the schemas aren't available in Content Delivery afaik, unless you put them there.– Alvin ReyesCommented Jun 18, 2013 at 19:12
3 Answers
I am guessing your issue is related to this:
I found that the titles of the schema's names are not actually deployed to the broker until at least one DCP based on that Schema has been published.
-
Hmm, I don't read the question this way. It looks like the OP is trying to create a query to get back the list of schema names. The other scenario is about getting DCPs based on a specific schema. Is the full list of schema names possible with the CD API in a single query? Commented Oct 1, 2013 at 7:10
Try this way:-
Query myQuery = new Query();
Criteria myCriteria = null;
ItemTypeCriteria isSchema = new ItemTypeCriteria(8);
PublicationCriteria pubCriteria = new PublicationCriteria(251);
AndCriteria andCriteria = new AndCriteria(isSchema, pubCriteria);
myCriteria = andCriteria;
myQuery.setCriteria(myCriteria);
SortParameter sortParameter = new SortParameter(SortParameter.ITEMS_SCHEMA_ID,
SortParameter.ASCENDING);
myQuery.addSorting(sortParameter);
//myQuery.setResultFilter(new LimitFilter(25));
String[] itemResults = myQuery.executeQuery();
System.out.println("RESULTS: " + itemResults.length);
Note that I haven't tested yet
You can, by default, publish pages and (dynamic) component presentations to content delivery along with their metadata (including template metadata now, I believe).
Schemas may be in the Broker database, but doing the following doesn't make sense (I'd expect components or pages):
ItemTypeCriteria IsSchema = new ItemTypeCriteria(ItemTypes.SCHEMA);
You can, however, get all CPs based on a specific schema:
SchemaTitleCriteria criteria = new SchemaTitleCriteria("article");
You could get the list of schemas in delivery by publishing out a configuration (xml) page or store it in a dcp. This might be a use case to use the Core Service in delivery, but I wouldn't recommend it.
You could also configure Tridion.ContentManager.config
to actually render schemas but you'd need a custom resolver along with whatever content delivery code you need to get this information. But it'd be easier to use a template building block assembly.
-
Schema Names are published along with DCPs, but not if the components are just embedded on a page Commented Jun 19, 2013 at 2:47
-
Makes sense. In my setup I can see at least two schemas in the schemas table but can't get them back via the API (without first getting the DCPs). Commented Jun 19, 2013 at 3:03
-
But I still doubt we can get the list of schemas in a single query. :-) Commented Oct 1, 2013 at 7:13