Search in sources :

Example 1 with EventDataObject

use of org.alfresco.bm.event.selector.EventDataObject in project records-management by Alfresco.

the class CreateRMSiteMember method processEvent.

@Override
protected EventResult processEvent(Event event) throws Exception {
    if (event == null) {
        throw new IllegalStateException("This processor requires an event.");
    }
    DBObject dataObj = (DBObject) event.getData();
    if (dataObj == null) {
        throw new IllegalStateException("This processor requires data with field " + FIELD_USERNAME);
    }
    String username = (String) dataObj.get(FIELD_USERNAME);
    EventProcessorResponse response = null;
    Event nextEvent = null;
    String msg = null;
    // Check the input
    if (StringUtils.isBlank(username)) {
        dataObj.put(MSG_KEY, INVALID_SITE_MEMBER_REQUEST_MSG);
        return new EventResult(dataObj, false);
    }
    // Get the membership data
    SiteMemberData siteMember = siteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, username);
    if (siteMember == null) {
        dataObj.put(MSG_KEY, MessageFormat.format(SITE_MEMBER_MISSING_MSG_TEMPLATE, username));
        return new EventResult(dataObj, false);
    }
    if (siteMember.getCreationState() != DataCreationState.Scheduled) {
        dataObj.put(MSG_KEY, MessageFormat.format(SITE_MEMBER_ALREADY_PROCESSED_MSG_TEMPLATE, siteMember));
        return new EventResult(dataObj, false);
    }
    // Start by marking it as a failure in order to handle all failure paths
    siteDataService.setSiteMemberCreationState(PATH_SNIPPET_RM_SITE_ID, username, DataCreationState.Failed);
    String roleStr = siteMember.getRole();
    try {
        // assign RM roles to new members as admin user
        RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI();
        rmUserAPI.assignRoleToUser(username, roleStr);
        siteDataService.setSiteMemberCreationState(PATH_SNIPPET_RM_SITE_ID, username, DataCreationState.Created);
        siteMember = siteDataService.getSiteMember(PATH_SNIPPET_RM_SITE_ID, username);
        EventDataObject responseData = new EventDataObject(STATUS.SUCCESS, siteMember);
        response = new EventProcessorResponse("Added RM site member", true, responseData);
        msg = MessageFormat.format(CREATED_RM_SITE_MEMBER_MSG_TEMPLATE, response);
        nextEvent = new Event(eventNameRMSiteMemberCreated, null);
    } catch (Exception e) {
        // Failure
        throw new RuntimeException("Create RM site member as user: admin failed (" + e.getMessage() + "): " + siteMember, e);
    }
    logger.debug(msg);
    EventResult result = new EventResult(msg, nextEvent);
    return result;
}
Also used : SiteMemberData(org.alfresco.bm.site.SiteMemberData) EventResult(org.alfresco.bm.event.EventResult) EventDataObject(org.alfresco.bm.event.selector.EventDataObject) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) RMUserAPI(org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI) EventProcessorResponse(org.alfresco.bm.event.selector.EventProcessorResponse)

Aggregations

DBObject (com.mongodb.DBObject)1 Event (org.alfresco.bm.event.Event)1 EventResult (org.alfresco.bm.event.EventResult)1 EventDataObject (org.alfresco.bm.event.selector.EventDataObject)1 EventProcessorResponse (org.alfresco.bm.event.selector.EventProcessorResponse)1 SiteMemberData (org.alfresco.bm.site.SiteMemberData)1 RMUserAPI (org.alfresco.rest.rm.community.requests.gscore.api.RMUserAPI)1