Java tutorial
/** * Copyright (C) 2005-2015 Alfresco Software Limited. * * This file is part of Alfresco * * Alfresco is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Alfresco is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with Alfresco. If not, see * <http://www.gnu.org/licenses/>. */ package org.alfresco.integrations.google.docs.webscripts; import java.util.HashMap; import java.util.Map; import com.google.api.client.auth.oauth2.Credential; import org.alfresco.integrations.google.docs.exceptions.GoogleDocsAuthenticationException; import org.alfresco.integrations.google.docs.exceptions.GoogleDocsRefreshTokenException; import org.alfresco.integrations.google.docs.exceptions.GoogleDocsServiceException; import org.alfresco.integrations.google.docs.service.GoogleDocsService; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.httpclient.HttpStatus; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Jared Ottley <jared.ottley@alfresco.com> */ public class HasConcurrentEditors extends GoogleDocsWebScripts { private GoogleDocsService googledocsService; private final static String MODEL_CONCURRENT_EDITORS = "concurrentEditors"; private final static String PARAM_NODEREF = "nodeRef"; public void setGoogledocsService(GoogleDocsService googledocsService) { this.googledocsService = googledocsService; } @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) { getGoogleDocsServiceSubsystem(); Map<String, Object> model = new HashMap<String, Object>(); String param_nodeRef = req.getParameter(PARAM_NODEREF); NodeRef nodeRef = new NodeRef(param_nodeRef); try { Credential credential = googledocsService.getCredential(); model.put(MODEL_CONCURRENT_EDITORS, googledocsService.hasConcurrentEditors(credential, nodeRef)); } catch (GoogleDocsAuthenticationException gdae) { throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdae.getMessage()); } catch (GoogleDocsRefreshTokenException gdrte) { throw new WebScriptException(HttpStatus.SC_BAD_GATEWAY, gdrte.getMessage()); } catch (GoogleDocsServiceException gdse) { if (gdse.getPassedStatusCode() > -1) { throw new WebScriptException(gdse.getPassedStatusCode(), gdse.getMessage()); } else { throw new WebScriptException(gdse.getMessage()); } } catch (Exception e) { throw new WebScriptException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e); } return model; } }