How to get category by name? - java

I recently work with commerce tools platform and I have such a question.
I have this query:
CompletionStage<List<Category>> stage = QueryExecutionUtils.queryAll(client, CategoryQuery.of().byName(Locale.ENGLISH, "cat1"));
final CompletableFuture<List<Category>> result = stage.toCompletableFuture();
return result.get().get(0);
Is there a way to return just a Category instead of List.get(0) and how it can be done?

Thanks for submitting this question. There is no unique constraint for the name field on categories. For this reason we cannot guarantee that the API will only return one result. With the name query you will get paged results and will have to pull the first entry from the list. Both key and id are both unique so you could query for either of those and get just the unique category. You can view the representation of categories in the docs here. https://docs.commercetools.com/http-api-projects-categories#category
Hope this helps!

Related

DynamoDB: how to query with multiple filter

I have a table and the structure looks like this:
my table structure
Here correlationId is my hashKey.
I can perform simple query using hashKey:
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDB);
Pickup itemRetrieved = mapper.load(Pickup.class, key);
Now I want to query on basis of fields i.e correlationId, partnerId to get transactionId.
How should I do that?
Here is the sample code with multiple filter.
List<Pickup> pickupList = null;
DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(dynamoDBClient);
Pickup pickup = new Pickup();
pickup.setCorrelationId(correlationId);
Map<String, AttributeValue> attributeValues = new HashMap<>();
attributeValues.put(":partnerId", new AttributeValue(partnerId));
DynamoDBQueryExpression<Pickup> queryExpression = new DynamoDBQueryExpression<Pickup>().withHashKeyValues(pickup)
.withFilterExpression("partnerId = :partnerId")
.withExpressionAttributeValues(attributeValues);
pickupList = dynamoDBMapper.query(Pickup.class, queryExpression);
pickupList.stream().forEach(i -> System.out.println(i.toString()));
Your partition key(correlation Id) is one keys on which you want to retrieve transactionid but it's missing partnerid.
Hence do these 3 steps
Step 1 - build a global secondary index on partnerid
Step 2 - filter on partition id
Step 3 - get transaction id
Query Filtering
DynamoDB’s Query function retrieves items using a primary key or an index key from a Local or Global Secondary Index. Each query can use Boolean comparison operators to control which items will be returned.
With today’s release, we are extending this model with support for query filtering on non-key attributes. You can now include a QueryFilter as part of a call to the Query function. The filter is applied after the key-based retrieval and before the results are returned to you. Filtering in this manner can reduce the amount of data returned to your application while also simplifying and streamlining your code.
The QueryFilter that you pass to the Query API must include one or more conditions. Each condition references an attribute name and includes one or more attribute values, along with a comparison operator. In addition to the usual Boolean comparison operators, you can also use CONTAINS, NOT_CONTAINS, and BEGINS_WITH for string matching, BETWEEN for range checking, and IN to check for membership in a set.
In addition to the QueryFilter, you can also supply a ConditionalOperator. This logical operator (either AND or OR) is used to connect each of the elements in the QueryFilter.

datastax java driver select + discardAll

Can I select and distinct in one query?
For example:
QueryBuilder
.select()
.all()
.from(Connector.KEY_SPACE_NAME, table)
.where(eq(this.uuidHotel, hotelUUID))
.discardAll(this.uuidHotel, javaList)
I cannot understand your column family structure. But your operation seems unusual.
You are querying for a field called uuidHotel, so I assume you are querying for UUID type in C*. It has to be the partition key, else you can't expect a result.
But you are also using discardAll on the same field. It can only be used on CollectionType fields.
https://docs.datastax.com/en/cql/3.0/cql/cql_using/use_collections_c.html
So it is unusual.
I think you are looking for is DISTINCT. Please refer to
http://docs.datastax.com/en/cql/3.1/cql/cql_reference/select_r.html
Hope it helps!

Retrieve Siebel data based on intersection table using SiebelDataBean

I have Siebel structure looking like this:
BusObj: Base
--BusComp: Category list
----BusComp: Product list
"Product list" is child component to "Category list", they have a link Category list/Product list by the means of intersection table 'S_CAT_PROD', that has CAT_ID for category and PROD_ID for product. This allows N-to-N linking of categories to products.
Now the problem is I have retrieved both SiebelBusComp from Java code, but have no idea how to make use of this intersection table to retrive all products for some category.
There are couple SiebelBusComp methods that return another SiebelBusComp, but I had no luck making them work. These are:
getAssocBusComp()
getMVGBusComp(java.lang.String fieldName)
getPicklistBusComp(java.lang.String fieldName)
parentBusComp()
Has anyone any experience using such logic in Java? Any help would be appreciated, thanks.
I couldn't find the table S_CAT_PROD in Siebel, assuming it is custom made. Again, assuming you have a M:M link from Catalog to Products correctly configured using this intersection table , the link itself will take care of filtering the child records based on parent category.
//make variable instances
var BO = TheApplication().GetBusObject("Base");
var bcCat = BO.GetBusComp("Category list");
var bcProd = BO.GetBusComp("Product list");
//search for category
bcCat.ClearToQuery();
bcCat.SetSearchSpec("Id", "1-234");
bcCat.ExecuteQuery(True);
// When using the ExecuteQuery method with Java Data Bean, use True for //ForwardOnly and False for ForwardBackward.
if (bcCat.FirstRecord())
{
//the link will automatically filter and bring only those products for this //category
bcProd.ClearToQuery();
bcProd.ExecuteQuery(True);
}

Datastore get not finding record by key

I've been banging my head against this for an embarrassing amount of time, and appreciate any help. I have what I think is a simple scenario where I'm trying to retrieve and update an entity if it exists, or create a new if it doesn't. There's a parent entity, and that part seems to work fine. I create the child key like this:
Key someKey = KeyFactory.createKey(parent.getKey(), CHILD_KIND, child.getUniqueStringValue());
According to the documents I read doing a get on this would return the entity if it existed:
Entity someChild = datastore.get(someKey);
But it doesn't. Instead I have to do a:
Query query = new Query(CHILD_KIND, someKey);
Entity someChild = datastore.prepare(query).asSingleEntity();
to find it. If I try to log the someKey.toString() value, they look the same during creation as they do during a search, but it still only finds them if I do the query instead of the get. I'm missing something stupid and obvious and searching has gotten me nowhere over the course of about a week, so I appreciate any help.
Thanks,
Mike
Edit:
To clarify how I'm creating the child entity, it's like this:
Key someKey = KeyFactory.createKey(parent.getKey(), CHILD_KIND, child.getUniqueStringValue());
Entity someChild = new Entity(CHILD_KIND, someKey);
someChild.setProperty("desc", child.getUniqueStringValue());
someChild.setProperty("createTime", child.getCreateTime());
// and then a few more values that are timestamps or null
There is a problem in the way you create a child entity. It should be:
Entity someChild = new Entity(CHILD_KIND, parent.getKey());
or
Entity someChild = new Entity(CHILD_KIND, child.getUniqueStringValue(), parent.getKey());
Also, I am not sure why you use child.getUniqueStringValue() instead of a simple Long id, which takes less space.
The problem is that you are confusing Parent_Key with Key.
This line:
Entity someChild = new Entity(CHILD_KIND, someKey);
Creates an Entity of the kind "CHILD_KIND" with parent entity of key "someKey". See this document for details [1].
When you do a simple datastore.get(key), you are using the Entity's own key, not the parent key. So what you need to do is use KeyFactory to get the Entity Key from its Parent Key, Kind, Name. The details can be found here [2] and here [3].
[1] - https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Entity
[2] - https://cloud.google.com/appengine/docs/java/datastore/entities#Java_Retrieving_an_entity
[3] - https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory

In Android API level 8, What's "person" column in "content://sms/inbox" matching to?

I query at Uri: "content://sms/inbox" for reading inbox sms. Then I got these two marjor columns returned (there're other columns which not related to my question so i just skip them):
*address - the from-person's phone number
*person - an id value. I thought it should map to column *id in Uri "ContactsContract.Contacts.CONTENT_URI"
I then query Uri: ContactsContract.Contacts.CONTENT_URI by condition: "id=person", hope to get the contact's display name, for some person, it works , but for many it doesn't - I then dig deeper and found there're a column "raw_contact_id" in Contacts Uri, and for those unmapped person value, it's actually mapping to this "raw_contact_id" value.
I wonder why would this happen? Shouldn't the id be unique for contact finding? Or did i miss something to make a full query to get display name by this *person value ??
Person column is the _id does not account for phone sync issues. There are multiple accounts contacts you have to make sure you are selecting the correct account type and then query Contacts.Contract for the given value. You may also try lookup_key to give you more info.
See http://developer.android.com/reference/android/provider/ContactsContract.html for info.

Categories