You are on page 1of 3

package com.acrowit.webscript.

search;
import java.util.Map;
import java.util.Set;
import javax.transaction.UserTransaction;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
import com.acrowit.api.service.alfresco.util.AcrowitAlfServiceUtil;
import com.acrowit.exception.AcrowitException;
import com.acrowit.exception.ErrorRepository;
import com.acrowit.transferobjects.Response;
import com.acrowit.util.AcrowitConstant;
import com.acrowit.util.JsonUtils;
import com.acrowit.util.StringUtils;
import com.acrowit.util.Version;
public class GetWitInfoTagSearchWs extends DeclarativeWebScript {
private TransactionService transactionService;
private AcrowitAlfServiceUtil acrowitAlfServiceUtil;
/**
* @param args
*/
private static final Log LOGGER = LogFactory.getLog(GetWitInfoTagSearchW
s.class);
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status statu
s)
{
String apiVersion = req.getServiceMatch().getTemplateVars().get("version
");

if (apiVersion == null)
{
apiVersion = "v0";
}
try
{
Version versionNumber = Version.valueOf(apiVersion);
switch (versionNumber)
{
case v0:
case v1:
return executeV1(req);
default:
return JsonUtils.getJsonString(new Response(ErrorRepository.
URL_INVALID.getError()));
}
}
catch (IllegalArgumentException ie)
{
LOGGER.error(StringUtils.stackTraceToString(ie), ie);
return JsonUtils.getJsonString(new Response(ErrorRepository.UNEXCEPT
ED_EXCEPTION.getError(" Version "
+ apiVersion + " is invalid. ", true)));
}
}
private Map<String, Object> executeV1(WebScriptRequest req)
{
UserTransaction userTransaction = transactionService.getUserTransaction(
);
try
{
userTransaction.begin();
System.out.println("================================================
===========");
System.out.println("Entered into the webscript and creating sample u
ser group");
//User Authentication process

if (!StringUtils.isNullOrEmpty(req.getParameter(AcrowitConstant.ACCE
SS_TOKEN)))
{
acrowitAlfServiceUtil.validateToken(req.getParameter(AcrowitCons
tant.ACCESS_TOKEN));
}

System.out.println("ticket validated");
String groupName = req.getParameter("groupName");
userTransaction.commit();
return JsonUtils.getJsonString(new Response("dd"));
}catch(AcrowitException ae){
LOGGER.error(StringUtils.stackTraceToString(ae),ae);
closeTransaction(userTransaction);
return JsonUtils.getJsonString(new Response(ErrorRepository.UNEXCEPT
ED_EXCEPTION.getError(ae.getMessage(),true)));
}
catch(Exception e){
// LOGGER.error(e.getMessage(),e);
LOGGER.error(StringUtils.stackTraceToString(e),e);
closeTransaction(userTransaction);
return JsonUtils.getJsonString(new Response(ErrorRepository.UNEXCEPT
ED_EXCEPTION.getError(e.getMessage(),true)));
}
}

private void closeTransaction(UserTransaction userTransaction)
{
if (userTransaction != null)
{
try
{
userTransaction.rollback();
}
catch (Exception ee)
{
LOGGER.error(StringUtils.stackTraceToString(ee),ee);
}
}
}
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
public void setAcrowitAlfServiceUtil(AcrowitAlfServiceUtil acrowitAlfSer
viceUtil) {
this.acrowitAlfServiceUtil = acrowitAlfServiceUtil;
}
public static void main(String[] args) {
}
}