Sunday, August 23, 2015

WebCenter Content RIDC Outlines

RIDC Call to Download File for Spring

1. Method to getFile

public Attachment getWCCFile(String dID,String dDocName,String username) throws IdcClientException, IOException{
IdcContext idcContext= new IdcContext(username);
IdcClient<IdcClientConfig, Protocol, Connection>  client = getIdcClient();
        DataBinder dataBinderReq = client.createBinder();
           dataBinderReq.putLocal("IdcService", "GET_FILE");
           dataBinderReq.putLocal("dID", dID);
           dataBinderReq.putLocal("dDocName", dDocName);
           dataBinderReq.putLocal("allowInterrupt", "1");
           dataBinderReq.putLocal("RevisionSelectionMethod", "LatestReleased");
           ServiceResponse  severiceResponse = client.sendRequest(idcContext, dataBinderReq);
           InputStream inputStream = severiceResponse.getResponseStream();
           byte[] bytes = IOUtils.toByteArray(inputStream);
    Attachment attachment = new Attachment(bytes,0,bytes.length);
    attachment.setContentType(severiceResponse.getHeader("Content-Type"));
    attachment.setFileName(severiceResponse.getHeader("filename"));
    attachment.setContentLength(severiceResponse.getHeader("Content-Length"));
 
    return attachment;
}

2.  Attachment Class
                  public class Attachment {
                     private byte[] content;
                     private int offset;
                     private int length;
                     private String contentType;
                     private String extension;
                     private String fileName;
                     private String contentLength;
                   }

3. Spring Controller

@RequestMapping(value = "/getDocument", method = RequestMethod.POST)
public ResponseEntity<byte[]> getDocument(@ModelAttribute("metaDataForm") MetaData metaData) {
logger.info(" In WCCController.getDocument() ");
try {
Attachment attachment = new RIDCHelper(ridcUrl,ridcPort,ucmPort).getWCCFile(metaData.getdID(), metaData.getdDocName(), metaData.getdDocAuthor());
return getResponse(metaData.getdDocName(),attachment);
} catch (IdcClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MimeTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

   private ResponseEntity<byte[]> getResponse(String dDocName,Attachment attachment) throws MimeTypeException{
    logger.info(" In WCCController.getResponse() ");
HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(attachment.getContentType()));
 
   Random rand = new Random(System.currentTimeMillis());
   MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
   MimeType extMime = allTypes.forName(attachment.getContentType());
   String ext = extMime.getExtension();

String randomFileName = "/"+dDocName+"_"+Math.abs(rand.nextLong()) + ext;
   headers.setContentDispositionFormData(randomFileName, randomFileName);
   headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
   ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(attachment.getContent(), headers, HttpStatus.OK);
   return response;
   }

4. Data save and retrieval through jdbc utility.

Save:-

 public void save(TransactionAction entity) throws Exception {
logger.info(" In TransactionActionDAOImpl.save(TransactionAction) ");
Object []statementParams = new Object[]{entity.getActionid(),entity.getName(),entity.getTitle(),entity.getTitlear(),
entity.getActiontype(),entity.getIsRequired()};
DataWorker dataWorker =  new DataWorker(addNew, null,statementParams);
try {
session.executeDataWorkers(dataWorker);
} catch (SQLException e) {
logger.error(" In TransactionActionDAOImpl.save(TransactionAction), Exception : "+e.getMessage());
throw e;
}

}

Update:-
public void update(TransactionAction entity)throws Exception {
logger.info(" In TransactionActionDAOImpl.update(TransactionAction) ");
Object []statementParams = new Object[]{new String(entity.getTitle().toUpperCase().replaceAll("\\s", "")),entity.getTitle(),entity.getTitlear(),
entity.getActiontype(),entity.getIsRequired(),entity.getActionid()};
DataWorker dataWorker =  new DataWorker(update, null,statementParams);
try {
session.executeDataWorkers(dataWorker);
} catch (SQLException e) {
logger.error(" In TransactionActionDAOImpl.update(TransactionAction), Exception : "+e.getMessage());
throw e;
}
}

FindAll:-

public TransactionAction findById(BigDecimal id) {
logger.info(" In TransactionActionDAOImpl.findById(BigDecimal), Action Id: "+id);
TransactionAction action = null;
try {
action = getSession().getEntity(findById,new TransactionAction(),id,Constants.ACTIVE);
} catch (SQLException e) {
logger.error(" TransactionActionDAOImpl.findById(BigDecimal), Action Id: "+id+", Exception : "+e.getMessage());
e.printStackTrace();
}
return action;
}


No comments:

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...