Getting All Workitems from Team Area - java

I have the following objects:
ITeamRepository repo;
IProjectArea projArea;
ITeamArea teamArea;
The process of obtaining the projArea and the teamArea is quite straightforward (despite the quantity of objects involved). However I can't seem to find a way to obtain a list with all the Workitems associated with these objects in a direct way. Is this directly possible, probably via the IQueryClient objects?

This 2012 thread (so it might have changed since) suggests:
I used the following code to get the work items associated with each project area:
auditableClient = (IAuditableClient) repository.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) repository.getClientLibrary(IQueryClient.class);
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(currProject, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, currProject);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(currProject, expression, IWorkItem.FULL_PROFILE);
In my code, currProject would be the IProjectArea pointer to the current project as you loop through the List of project areas p in your code.
The IQueryResult object 'results' then contains a list of IResolvedResult records with all of the work items for that project you can iterate through and find properties for each work item.

Related

How to get all the assets in a Smart Collection in AEM?

I am trying to get all the assets inside a smart collection in AEM given the path of the smart collection.
I could do this for a normal collection by getting the node paths under sling:members
But how to get all the assets of a Smart Collection
The data under sling:members is empty because of which my code works only for normal collections but not Smart Collection
I expect to get all the assets under for a smart Collection given the path of the smart collection in java
Here is a simple snippet you can run with AEM Groovy Console:
// https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/com/day/cq/dam/api/collection/SmartCollection.html
import com.day.cq.dam.api.collection.SmartCollection;
import com.day.cq.dam.api.Asset;
def SMART_COLLECTION_PATH = "/content/dam/collections/J/Jx4h69ABp_KoLbZJ-8dq/test-collection";
def smartCollectionResource = getResource(SMART_COLLECTION_PATH)
def smartCollection = smartCollectionResource.adaptTo(SmartCollection.class)
smartCollection
.getQuery()
.getResult()
.getNodes()
.each {
def assetResource = getResource(it.path);
def asset = assetResource.adaptTo(Asset.class)
println asset.path
}
The basic gist is that you can get the smart collection resource then adapt it to a SmartCollection from there you can call getQuery, execute the query, get the nodes and adapt them to Asset objects or just process the nodes directly. In the code above, I print the asset paths.
Even thought the code above is groovy, it is simple enough that you could convert it to java very quickly.

How am I supposed to extract properties from a node in Apache Jackrabbit from xml?

I have been playing around with the example number three in here http://jackrabbit.apache.org/jcr/first-hops.html , however to me it remains unclear how to get access to the properties of a node.
In the first screenshot
I used the debugger from my IDE and I evaluated this expression
session.getNode("/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn").getProperty("jcr:xmltext/jcr:xmlcharacters").getString().trim();
You can see how I can get access to "jcr:xmltest/jcr:xmlcharacters" and have 2 as a result.
However, when I try to get this information, get this property out of the node, I am unable to perform this operation as in this screenshot.
This is the code fragment in the above screenshot:
var node = session.getNode("/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn");
var properties = node.getProperties();
List<string> result = new ArrayList<>();
while(properties.hasNext()) {
Property property = properties.nextProperty();
result.add(property.getString().trim());
}
return result;
You can see how I get as a response only a value containing "nt:unstructured".
Unfortunately I couldn't find many code examples online, on Github, etc. many outdated, and also, there are not books as there are for Scrapy or other libraries/frameworks.
Thank you in advance.
Have a nice day!
Davide
In the first case, you are looking at the properties of:
/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn/jcr:xmltext
In the second case:
/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn
Note the different paths.

Get product info in promotions applied in Hybris

I want to learn which promotions were applied to which products on promotionengine in order to distribute prices on products amongst themselves and send them to ERP.
When we look at the promotionService in Hybris, there is a method called getPromotionResults(order). It returns PromotionOrderResults object. In this object, two methods are related to my case, getAppliedProductPromotions() and getAppliedOrderPromotions().
If I did not miss it, I could not see product info for a promotion in these methods' results. Also, I looked at all attributes via promotion.getAppliedOrderPromotions().get(0).getAllAttributes() but i could not have them.
How can I know product info and discount amount in a promotion?
The method you are looking for is
PromotionOrderResults#getAppliedProductPromotions()
This will return all the promotions applied to order entries / products, you can navigate to the products via PromotionOrderEntryConsumed PromotionResult#getConsumedEntries()
I have a way to get the product that was Added as free gift on a promotion... Usually is something like this
Set promotionResultModels = cart.getAllPromotionResults();
if (!Objects.isNull(promotionResultModels))
{
Iterator resultsIterator = promotionResultModels.iterator();
while (resultsIterator.hasNext())
{
PromotionResultModel promoResultModel = (PromotionResultModel) resultsIterator.next();
Iterator var6 = promoResultModel.getActions().iterator();
while (var6.hasNext())
{
AbstractPromotionActionModel action = (AbstractPromotionActionModel) var6.next();
if (action instanceof RuleBasedOrderAddProductActionModel)
{
String freeGiftProductCode = ((RuleBasedOrderAddProductActionModel) action).getProduct().getCode();
}
}
}
}
However in my scenario, this is Free Gift promotion, not sure if the Bundle Based Promotion might have similar properties. As per the product that actually FIRED the promotion, I'm still looking a way to get it. The closest I've been is with this:
((RuleBasedOrderAddProductActionModel) action).getRule().getRuleContent()
However that's the Hybris Generated Code that has the RAO's and the product codes are buried within that string. So I needed to write an ugly script parser to find the codes.
Let me know if you find out the second part, the Products that triggered the promos, I'm still looking for it too.

OrientDB getVertices not working with Java-generated class/index

Summary
I'm playing around with OrientDB for a proof of concept, and I'm having some trouble querying a class/composite index generated through the Java API.
I created the class, added a few properties and generated the composite index using the API, then added a sample record. I verified that everything looked okay using the Studio. I then used getVertices(String label, String[] keys, Object[] values) to try to pull my sample record, but didn't get any results.
I purged the index and class and recreated them using the Studio UI, ran the getVertices code and the record was retrieved successfully.
In the course of my investigation, I also recreated the class/index using the Java API and provided an incorrect label (a class created via the UI that extended V) and the record was retrieved successfully, which was weird.
Why is the the Java-created class/index behaving differently than the one I made in the UI? Am I doing something wrong?
Environment Background
I'm using OrientDB Enterprise 2.0.3 and the 2.0.x orientdb-* and blueprints-core jars.
Details
I'm creating the class/index in Java kind of like this (shortened for simplicity, strings changed to protect the innocent):
//graph is an OrientGraph
//Create a new class that extends V
OClass vt = graph.createVertexType("MyClass", "V");
String[] props = {"first", "second", "third"}; //Property names
for(String prop : props)
vt.createProperty(prop, OType.STRING);
//Create unique composite index using all properties
vt.createIndex("myClass.myIndex", OClass.INDEX_TYPE.UNIQUE, props);
graph.commit();
I added records to the graph like this and confirmed that they showed up in Studio (select * from MyClass):
Vertex v = graph.addVertex("class:MyClass");
v.setProperty("first", "foo");
v.setProperty("second", "bar");
v.setProperty("third", "ed");
graph.commit();
To query the graph, I'm using this:
String[] keys = {"first", "second", "third"};
String[] values = {"foo", "bar", "ed"};
//Using getVertices to get records from a specific class with specified key values.
//There could be multiple classes with the same properties, so I have to be able
//to look for a set of properties within a specific class.
Iterable<Vertex> resultIterator = graph.getVertices("MyClass", keys, values);
for (Vertex v : resultIterator){
results.add(v); //Store result references for later use
}
Also, I did confirm that graph.isUseClassForVertexLabel() was true.
When I run graph.getVertices("MyClass",keys,values), nothing comes back.
If I run graph.getVertices("DummyClass",keys,values) where DummyClass is a random class created in Studio that extends V and has completely different properties than MyClass, I get results. This case kind of scares me, because there could eventually be multiple classes with the same properties, and I have to be able to query records from a specific class with a property set - I don't want to pull in results from a bunch of different classes...
If I recreate MyClass from the Studio UI and run graph.getVertices("MyClass",keys,values), I get the expected results.
I created an issue (#3889) for this on the OrientDB repo. It has been fixed.

Upsert for LDAP directory in Java

I'm attempting to execute an Upsert using the Novell JLDAP library, unfortunately, I'm having trouble finding an example of this. Currently, I have to:
public EObject put(EObject eObject){
Subject s = (Subject) eObject;
//Query and grab attributes from subject
LDAPAttributes attr = resultsToAttributes(getLDAPConnection().get(s));
//No modification needed - return
if(s.getAttributes().equals(attr)){
return eObject;
} else {
//Keys:
//REPLACE,ADD,DELETE, depending on which attributes are present in the maps, I choose the operation which will be used
Map<String,LDAPAttribute> operationalMap = figureOutWhichAttributesArePresent(c.getAttributes(),attr);
//Add the Modifcations to a modification array
ArrayList<LDAPModification> modList = new ArrayList<LDAPModification>();
for(Entry entry: operationalMap.getEntrySet()){
//Specify whether it is an update, delete, or insert here. (entry.getKey());
modList.add(new LDAPModification(entry.getKey(),entry.getValue());
}
//commit
connection.modify("directorypathhere",modList.toArray(new LDAPModification[modList.size()]));
}
I'd prefer to not have to query on the customer first, which results in cycling through the subject's attributes as well. Is anyone aware if JNDI or another library is able to execute an update/insert without running multiple statements against LDAP?
Petesh was correct - the abstraction was implemented within the Novell library (as well as the UnboundId library). I was able to "upsert" values using the Modify.REPLACE param for every attribute that came in, passing in null for empty values. This effectively created, updated, and deleted the attributes without having to parse them first.
In LDAP, via LDIF files, an upset would be a single event with two steps. A remove and add of a value. This is denoted by a single dash on a line, between the remove then the add.
I am not sure how you would do it in this library. I would would try to modList.remove and then modList.add one after another and see if that works.

Categories