Alfresco CMIS query checking for NULL/Blank - alfresco

I want to check whether the Aspect property is present or not and if present it should not be blank... On some docs the aspect applied but no properties are populated. On some docs all the properties of aspect are populated but few are blank.
I tried below queries..
select * from myType:myCase as d join myAspect:myTest as p on d.cmis:objectId = p.cmis:objectId WHERE
CONTAINS(d, 'PATH:"//app:company_home/cm:DROP-FOLDER/*"')
AND p:myAspect:caseId = ''
I also tried
p:myAspect:caseId = <> ''
**p:myAspect:caseId IS NOT NULL (Doesn't give error but return the row with blank property value)
In short how can I check whether the aspect property is present or not and if present it is not blank?
Thank you

I'm not sure I understand what you mean by "if present it should not be blank" (you're probably thinking about properties). If you want to check whether some aspect is there, this in an option:
SELECT * FROM cmis:document where contains('ASPECT:\'myNs:myAspect\'')
Be careful about transactional queries, though.
http://docs.alfresco.com/5.0/concepts/intrans-metadata-query.html

you can make a query as below to get the documents that doesn't have specific aspect, just an update to #Lista's answer
SELECT * FROM myType:myCase WHERE NOT CONTAINS('ASPECT:\'myNs:myAspect\'')

Related

Cosmos db Order by on 'computed field'

I am trying to select data based on a status which is a string. What I want is that status 'draft' comes first, so I tried this:
SELECT *
FROM c
ORDER BY c.status = "draft" ? 0:1
I get an error:
Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path
I checked Microsoft site and I see this:
The ORDER BY clause requires that the indexing policy include an index for the fields being sorted. The Azure Cosmos DB query runtime supports sorting against a property name and not against computed properties.
Which I guess makes what I want to do impossible with queries... How could I achieve this? Using a stored procedure?
Edit:
About stored procedure: actually, I am just thinking about this, that would mean, I need to retrieve all data before ordering, that would be bad as I take max 100 value from my database... IS there any way I can do it so I don t have to retrieve all data first? Thanks
Thanks!
ORDER BY item expression could not be mapped to a document path.
Basically, we are told we can only sort with properties of document, not derived values. c.status = "draft" ? 0:1 is derived value.
My idea:
Two parts of query sql: The first one select c.* from c where c.status ='draft',second one select c.* from c where c.status <> 'draft' order by c.status. Finally, combine them.
Or you could try to use stored procedure you mentioned in your question to process the data from the result of select * from c order by c.status. Put draft data in front of others by if-else condition.

Datastore: `SELECT * FROM Entity WHERE property IS NULL` returns no result despite entities without property

I am using Google Cloud Datastore and successfully stored entities.
Now I am trying to query them based on the presence of a property.
I use the "Query by GQL" tab in the Datastore UI: https://console.cloud.google.com/datastore/entities/query/gql
For some entities, I did not specify the property property when I saved them, so I expect these to be set to NULL.
However, when I query SELECT * FROM Entity WHERE property IS NULL, no result is returned.
This is working as intended:
According to the Datastore documentation:
Null is a value, not the absence of a value.
There is no way to determine whether an entity lacks a value for a property (that is, whether the property has no value). If you use a condition of the form nonexistent = NULL, what will occur is a check whether a null value is explicitly stored for that property. For example, SELECT * FROM Task WHERE nonexistent = NULL will never yield an entity with no value set for property nonexistent.
So to explicitly retrieve entities with property set to NULL, you would have to store the property: NULL for these entities.
What you are trying to achieve is not possible. NULL is not the same as property not present.
But as mentioned by Nick Johnson here,
The workaround would be to provide a default value for the updated property, and query for that value
I haven't tried this personally, and I am not sure if it works, but I suggest you to try this.
If it doesn't work, the only other option is to go through every record of the model and update all the existing entities which do not have a value, with a default value.

CMIS aspect query with path

I need to query a particular folder in the repository using a java based scheduler in alfresco.
I need to check whether the custom aspect's property is present or not.
Below query works for me when I don't use the path query.
select * from myType:caseDoc as d join myAspect:caseId as s on d.cmis:objectId = s.cmis:objectId
The problem with the above query is it searches all the contents in the repository but I want to target a particular folder.
When I try to put the CONTAINS in the above query it fails.
select * from cch:caseDoc as d
join cch:caseId as s on d.cmis:objectId = s.cmis:objectId WHERE CONTAINS('PATH:"//app:company_home/cm:FWED/cm:CDO/cm:CAB-DROP-FOLDER/*"')
It gives below exception
A selector must be specified when there are two or more selectors
Thank you
It looks like you may be missing one argument in CONTAINS(). Did you try something like this?
select *
from cch:caseDoc as d
join cch:caseId as s
on d.cmis:objectId = s.cmis:objectId
WHERE CONTAINS(d,'PATH:"//app:company_home/cm:FDLE/cm:CCH/cm:CCH-D‌​ROP-FOLDER/*"')
(I'm just putting my comment as an answer)
Well, if you are worrying about the path, then you should put
CONTAINS('PATH:"/app:company_home/cm:FWED/cm:CDO/cm:CAB-DROP-FOLDER/*"')
With one single / at the start of the path, if you which to only search in direct children to that path or :
CONTAINS('PATH:"/app:company_home/cm:FWED/cm:CDO/cm:CAB-DROP-FOLDER//*"')
to perform the lookup in the whole underlying hierarchy!
However, I do think that the query you provided and the behaviour you described does not match each other !

EMC Documentum DQL - How to delete repeating attribute

I have a few objects created on my database and I need to delete some of the repeating attributes related to them.
The query I'm trying to run is:
UPDATE gemp1_product objects REMOVE ingredients[1] WHERE (r_object_id = '08015abd8002cd68')
But all I get is the folloing error message:
Error querying databse.
[DM_QUERY_E_UPDATE_INDEX]error: "UPDATE: Unable to REMOVE tghe attribute ingredients at index 1."
[DM_OBJECT_W_DELETE_ATTR_POSITION_ERROR]warning: "attempt to delete
non-existent attribute 88"
Object 08015abd8002cd68 exists and I can see it on the database. Queries like SELECT and DELETE work fine but I do not want to delete the whole object.
There is no easy way to do this. The reason is that repeating attributes are ordered, to enable multiple repeating attributes to be synchronized for a given object.
Either
set the attribute value to be empty for the given position, and change your code to discard empty attributes, or
use multiple DQL statements to shuffle the order so that the last one becomes empty, or
change your data model, e.g. use a single attribute as a property bag with pre-defined delimiters.
Details (1)
UPDATE gemp1_product OBJECTS SET ingredients[1] = '' WHERE ...
Details (2)
For each index; first find the value of index+1:
SELECT ingredients
FROM gemp1_product
WHERE (i_position*-1)-1 = <index+1>
ENABLE (ROW_BASED)
Use the value in a new query:
UPDATE gemp1_product OBJECTS SET ingredients[1] = '<value_from_above>' WHERE ...
It should also be possible to do this by nesting DQL somehow, but it might not be worth the effort.
Something is either wrong with your query or with your repository. I think you are mistyping your attribute name or using wrong index in your UPDATE query.
If you google for DM_OBJECT_W_DELETE_ATTR_POSITION_ERROR you'll see on this link a bit more detailed explanation:
CAUSE: Program executed a DeleteAttr operation that specified an non-existent attribute position (either a negative number or a number larger than the number of attributes in the object).
From this you could guess that type isn't in consistent state, or that you are trying to remove too big index of your repeating attribute, etc. Did you checked your repository with Consistency checker Job and other similar Jobs?
As of for the removing of repeating property (sttribute) value with DQL query, this is unachievable with single query since you need to specify index position which you don't know at first. But writing a simple script or doing it manually if it's not big amount of values to delete is the way you want to go.

sqlite copy values within a table

I'm completely new to sqlite, so bear with me. I am updating a database and need to copy values within the same table, named "custom". I used pragma to get the table info, it's:
0|ticket|integer|0||0
1|name|text|0||0
2|value|0||0
Using select * from custom where ticket = (some value) I get, among other results,
(some value)|block|
(some value)|required|(another value)
I want to copy (another value) to "block" anywhere this value exists in "required". How do I make that happen? Everything I've tried has failed miserably to this point.
My pseudo code version would be something like
update custom
where required has a value
copy it to block
How do I turn that into actual sqlite commands?
UPDATE custom
SET value = (SELECT value
FROM custom AS c2
WHERE c2.ticket = custom.ticket
AND c2.name = 'required')
WHERE name = 'block'
AND value IS NULL

Resources