How to find all the files of a particular model in Alfresco - alfresco

Good morning. I have a task to make a request that would find all the documents of a certain type. After receiving the result, I need to display the fields of all found documents in the table. How can I do that? Thanks for answers.

You can use Lucene query to find all folders of the specific type.

To retrieve all documents of a certain type you can use Lucene query, this is a working example of query to get all nodes with type ipt:delegation using java.
String query = "TYPE:\"ipt:delegation\"";
SearchParameters sp = new SearchParameters();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
sp.addStore(storeRef);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(query);
ResultSet results = null;
try {
results = searchService().query(sp);
for (ResultSetRow row : results) {
NodeRef nodeRef = row.getNodeRef();
// do your work -
}
}
And to retrieve document fields you can use nodeService.getProperties(nodeRef).

Related

CMIS query is working in alfresco node browser but not in session.query()

I am using below code for retrieving some object based on creation date
String query = ContentCleaningUtil.buildQuery(fileNamePattern, uTCTimeString);
OperationContext opCon = session.createOperationContext();
opCon.setLoadSecondaryTypeProperties(true);
opCon.setMaxItemsPerPage(1000);
ItemIterable<QueryResult> results = session.query(query, false, opCon);
I am getting empty results.
The query String is:
SELECT * FROM cmis:document WHERE cmis:name LIKE '%.zip' AND cmis:creationDate > TIMESTAMP '2018-09-01T22:56:44.248Z'
But when I am firing same query in alfresco node browser setting query as cmis-alfresco, it is returning 2 desired objects.
In both case I am using store workspace://Spacestore
Can anyone please help on this.

Delete filter record in objectify datastore

i want to delete record where company_id is "****" and gamer_id is "****".
How to write query for this .
public List<CompanyGamer> unfollowcompany(CompanyGamerForm CompanyGamerForm) throws NotFoundException {
String company_id = CompanyGamerForm.getCompany_id();
String gamer_id = CompanyGamerForm.getGamer_id();
Iterable<Key<CompanyGamer>> allKeys = ofy().load().type(CompanyGamer.class).filter("company_id=", company_id).filter("gamer_id=", gamer_id).keys();
ofy().delete().keys(allKeys); }
Please let me know what should be define in return ?
Have a look at the Objectify documentation for Queries https://github.com/objectify/objectify/wiki/Queries at the bottom of section "Executing Queries". "You can query for just keys, which will return Key objects much more efficiently than fetching whole objects"
Iterable<Key<Gamercompany>> allKeys = ofy().load().type(Gamercompany.class).filter("company_id=", compnyid).filter("gamer_id=",gamer_id).keys();
And then you can delete all entities corresponding to the keys:
ofy().delete().keys(allKeys);
Or if you do want to execute the query that returns the entities and not the keys, you could iterate over the Query and do:
ofy().delete().entity(thing); // asynchronous
or
ofy().delete().entity(thing).now(); // synchronous
However it would be less efficient than the first way.

Linq to Entities does not recognize the method collection Dictionary

I have a model named EmailDetailModel with a Dictionary field.
My query is:
var query = from email in context.EmailModel
where rolesForUser.Contains(email.GroupName)
orderby email.Id descending
select new EmailDetailModel()
{
From = email.From,
Id = email.Id,
message = email.Body,
subject = email.Subject,
pathFileName =
(from pdf in context.PdfModel
where pdf.Email_Id == email.Id
select pdf)
.ToDictionary(k => k.PathFile, v => v.FileName),
timeSend = email.ActiveTime};
However an error occurs on this line when trying to send the list to the view:
View(query.ToPagedList(pageNumber, pageSize));
Saying that:
LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary
If anybody could help me, I'm not sure how I can pass the key and value into my pathFileName Dictionary.
The issue likely is that there is no SQL like conversion of the dictionary generation that LINQ to Entities can understand.
I have struggled with similar error messages whenever LINQ cannot be translated to a SQL statement.

Updating Cassandra Map Value through querybuilder

Cassandra support updating specific value in Collection by syntax
ALTER TABLE users ADD todo map<timestamp, text>
UPDATE users SET todo['2012-10-2 12:00'] = 'throw my precious into mount doom'
WHERE user_id = 'frodo';
http://www.datastax.com/documentation/cql/3.0/cql/cql_using/use_map_t.html
Did not see any example of using QueryBuilder to update specific row in Map. How it can be done?
I think you have several options.
1/ Build your own query based on the CQL one.
Example: Consider that you have a table named Interactions and in your schema a column of type named 'attributes'.
String update ="UPDATE demo.Interactions SET attributes=attributes + {'i':'j'} where id='ff';
SimpleStatement statement = new SimpleStatement(update);
session.execute(statement);
2/ Use Java API.
Java API is not that documented indeed.
Let's take an example
a- Create an update object using queryBuilder
Update update = QueryBuilder.update(keyspace, tableName);
b- Then populate with 'put' or 'putAll' functions. put/putAll will add/update content
update.with(QueryBuilder.putAll(key, map));
To remove a key, set the content of a key to null, like:
for (Object item : map.keySet()) {
update.with(
QueryBuilder.put(columName, item, null)
);
}
Then execute the query.
Following methods are available for different types:
LIST:
QueryBuilder.appendAll(...)
QueryBuilder.discardAll(...)
SET:
QueryBuilder.addAll(...)
QueryBuilder.removeAll(...)
MAP:
QueryBuilder.putAll(...)
QueryBuilder.put(...)
The list is not exhautive.
Have a look in QueryBuilder class if you do not find what you are looking for.
Best regards and best luck with Cassandra.

Different RavenDB collections with documents of same type

In RavenDB I can store objects of type Products and Categories and they will automatically be located in different collections. This is fine.
But what if I have 2 logically completely different types of products but they use the same class? Or instead of 2 I could have a generic number of different types of products. Would it then be possible to tell Raven to split the product documents up in collections, lets say based on a string property available on the Product class?
Thankyou in advance.
EDIT:
I Have created and registered the following StoreListener that changes the collection for the documents to be stored on runtime. This results in the documents correctly being stored in different collections and thus making a nice, logically grouping of the documents.
public class DynamicCollectionDefinerStoreListener : IDocumentStoreListener
{
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata)
{
var entity = entityInstance as EntityData;
if(entity == null)
throw new Exception("Cannot handle object of type " + EntityInstance.GetType());
metadata["Raven-Entity-Name"] = RavenJToken.FromObject(entity.TypeId);
return true;
}
public void AfterStore(string key, object entityInstance, RavenJObject metadata)
{
}
}
However, it seems I have to adjust my queries too in order to be able to get the objects back. My typical query of mine used to look like this:
session => session.Query<EntityData>().Where(e => e.TypeId == typeId)
With the 'typeId' being the name of the new raven collections (and the name of the entity type saved as a seperate field on the EntityData-object too).
How would I go about quering back my objects? I can't find the spot where I can define my collection at runtime prioring to executing my query.
Do I have to execute some raw lucene queries? Or can I maybe implement a query listener?
EDIT:
I found a way of storing, querying and deleting objects using dynamically defined collections, but I'm not sure this is the right way to do it:
Document store listener:
(I use the class defined above)
Method resolving index names:
private string GetIndexName(string typeId)
{
return "dynamic/" + typeId;
}
Store/Query/Delete:
// Storing
session.Store(entity);
// Query
var someResults = session.Query<EntityData>(GetIndexName(entity.TypeId)).Where(e => e.EntityId == entity.EntityId)
var someMoreResults = session.Advanced.LuceneQuery<EntityData>(GetIndexName(entityTypeId)).Where("TypeId:Colors AND Range.Basic.ColorCode:Yellow)
// Deleting
var loadedEntity = session.Query<EntityData>(GetIndexName(entity.TypeId)).Where(e =>
e.EntityId == entity.EntityId).SingleOrDefault();
if (loadedEntity != null)
{
session.Delete<EntityData>(loadedEntity);
}
I have the feeling its getting a little dirty, but is this the way to store/query/delete when specifying the collection names runtime? Or do I trap myself this way?
Stephan,
You can provide the logic for deciding on the collection name using:
store.Conventions.FindTypeTagName
This is handled statically, using the generic type.
If you want to make that decision at runtime, you can provide it using a DocumentStoreListner

Resources