core.engine.api.ResourceDocumentBuilder Maven / Gradle / Ivy
package core.engine.api;
import org.glassfish.jersey.server.model.Resource;
import java.util.List;
/**
* Created by nitina on 5/14/16.
*/
public class ResourceDocumentBuilder {
private StringBuilder resourceDocument;
private StringBuilder resourceInvalidApiDocument;
public static final String docHeader = "Resource API Documents API Doc
Resource Path Resource Method Resource Consume Type Resource Produces Type ";
public static final String docFooter = "
";
public ResourceDocumentBuilder(){
resourceDocument = new StringBuilder();
resourceInvalidApiDocument = new StringBuilder();
}
/***
* Create Table view of API documents
* @param resourceList
*/
public void addResourceValidInformation(List resourceList,String serviceURI){
resourceDocument.append(docHeader);
for(Resource resource : resourceList){
addResourceValidInformation(resource,serviceURI);
}
}
private void addResourceValidInformation(Resource resource,String serviceURI){
resourceDocument.append("");
resourceDocument.append(serviceURI + resource.getPath());
resourceDocument.append(" ");
resourceDocument.append(resource.getResourceMethods().get(0).getHttpMethod());
resourceDocument.append(" ");
resourceDocument.append(resource.getResourceMethods().get(0).getConsumedTypes().get(0).toString());
resourceDocument.append(" ");
resourceDocument.append(resource.getResourceMethods().get(0).getProducedTypes().get(0).toString());
resourceDocument.append(" ");
}
public void addResourceInvalidInformation(String invalidInfo){
resourceInvalidApiDocument.append("");
resourceInvalidApiDocument.append(invalidInfo);
resourceInvalidApiDocument.append(" ");
}
public void updateResourceInvalidInformation(String invalidInfo){
resourceInvalidApiDocument.append("");
resourceInvalidApiDocument.append("" + invalidInfo + "");
resourceInvalidApiDocument.append(" ");
}
public void addResourceDocInvalidInfo(String invalidInfo){
resourceDocument.append(docHeader);
resourceDocument.append("");
resourceDocument.append(invalidInfo);
resourceDocument.append(" ");
resourceDocument.append(docFooter);
}
public String getResourceDocument() {
if(resourceInvalidApiDocument.length()>0){
return resourceDocument.toString() + resourceInvalidApiDocument.toString() + docFooter;
}
return resourceDocument.toString() +docFooter;
}
}