04-03-2015 06:19 AM
Hello! I have implemented a scheduler associated with an event. I would like to search documents inside it with the session. Unfortunately when I try to get the session from the event it returns null. There's the code of my scheduler:
<?xml version="1.0"?>
<component name="fr.sword.bdf.arche.distribution.core.schedule">
<extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
point="schedule">
<schedule id="embargoSchedule">
<eventId>EmbargoEvent</eventId>
<eventCategory>default</eventCategory>
<!-- Every 2 minutes -->
<cronExpression>0 0/2 * 1/1 * ? *</cronExpression>
</schedule>
</extension>
</component>
The code of my event contrib:
<?xml version="1.0"?>
<component name="fr.sword.bdf.arche.distribution.core.event">
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
point="listener">
<listener name="EmbargoEvent" async="false" postCommit="true"
priority="140" class="fr.sword.bdf.arche.distribution.core.event.EmbargoEvent">
<event>EmbargoEvent</event>
</listener>
</extension>
</component>
And the code of the event listener:
public class EmbargoEvent implements EventListener {
private static final Log LOG = LogFactory.getLog(EmbargoEvent.class);
public static final String EVENT_NAME = "EmbargoEvent";
protected Lock lock = new ReentrantLock();
@Override
public void handleEvent(Event event) throws ClientException {
if (event != null && EVENT_NAME.equals(event.getName())) {
final EventContext context = event.getContext();
final CoreSession session = context.getCoreSession();
List<DocumentModel> docs = getDocListEmbargo(session, event);
LOG.error("Size docs: " + docs.size());
}
}
public static List<DocumentModel> getDocListEmbargo(CoreSession session, Event event) throws ClientException {
try {
List<DocumentModel> results = new ArrayList<DocumentModel>();
// Requête de récupération des documents statut
final StringBuilder query = new StringBuilder("SELECT * FROM ");
query.append(DocumentConstants.DOCUMENT_EXTERNE_DOC_TYPE);
query.append(" WHERE ");
query.append(DocumentConstants.DOCUMENT_EXTERNE_SCHEMA_PREFIX);
query.append(" AND ");
query.append("ecm:isProxy = 0 ");
query.append(" AND ");
query.append("ecm:currentLifeCycleState != 'deleted' ");
query.append(" AND ");
query.append("(dext:niveauConfidentialite = 2 OR dext:niveauConfidentialite = 3) ");
final DocumentModelList docs = session.query(query.toString());
for (int i = 0; i < docs.size(); i++) {
results.add(docs.get(i));
}
return results;
} catch (Exception e) {
event.markRollBack(null, e);
throw new ClientException(e);
}
}
}
Thank you in advance.
04-03-2015 06:33 AM
Forget about it I found the solution thanks to this link: https://github.com/easysoa/EasySOA/wiki/Nuxeo-CoreSession-and-Transactions
01-20-2016 09:29 AM
[pmbroca](https
06-06-2016 06:14 AM
just need a help...just need to know if you have created the scheduler as a nuxeo component and the listener as a document listener?
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.