07-16-2012 05:06 AM
Hi all,
I have created a seam validator:
public void validateSAPNumber(FacesContext context, UIComponent component,
Object value) {
String messageString = null;
Integer size = 1;
String SAPNumber = (String) value;
String DocId = navigationContext.getCurrentDocument().getId();
String query = String.format("SELECT * FROM Document WHERE sap:SAPNumber = '%s' AND ecm:uuid != '%s'", SAPNumber, DocId);
try {
DocumentModelList docs = documentManager.query(query);
size = docs.size();
} catch (Exception e) {
messageString = "label.org.nuxeo.adambo.sap.SAPNumberActionsBean";
}
if (size>0) {
FacesMessage message = new FacesMessage(
FacesMessage.SEVERITY_ERROR, ComponentUtils.translate(
context, "label.org.nuxeo.adambo.sap.SAPNumberActionsBean"),
null);
context.addMessage(null, message);
throw new ValidatorException(message);
}
}
and it works but only with a user permissions scope. The problem is that the "query" method uses a "FilteresQuery" class. I guess it is necessary to use the "createQuery" method of the "Session" class, but how get access to it? The simple conversion of the documentManager to a "Session" class is not possible.
07-16-2012 12:22 PM
Ok, I have realised the Query method in this way:
try {
String repoName = documentManager.getRepositoryName();
LocalSession lsession = new LocalSession();
lsession.connect(repoName, null);
Session session = lsession.getSession();
Query compiledQuery = session.createQuery(query, Query.Type.NXQL);
QueryResult results = compiledQuery.execute();
DocumentModelList dms = results.getDocumentModels();
return dms;
} catch (Exception e) {
throw new ClientException("Failed to execute query.", e);
}
I am not sure that it is the best and simplest solution, but it works. Maybe it will help someone else.
Best regards
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.