private static Logger logger = LoggerFactory.getLogger(KarmaServlet.class);
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
KarmaMetadataManager metadataManager = null;
UpdateContainer updateContainer = new UpdateContainer();
try {
metadataManager = new KarmaMetadataManager();
metadataManager.register(new UserUploadedMetadata(), updateContainer);
metadataManager.register(new UserPreferencesMetadata(), updateContainer);
metadataManager.register(new UserConfigMetadata(), updateContainer);
} catch (KarmaException e) {
logger.error("Unable to complete Karma set up: ", e);
}
/* Check if any workspace id is set in cookies. */
boolean hasWorkspaceCookieId = false;
String hasPrefId = request.getParameter(Arguments.hasPreferenceId.name());
if(hasPrefId != null && hasPrefId.equals("true"))
hasWorkspaceCookieId = true;
Workspace workspace = null;
VWorkspace vwsp = null;
/* If set, pick the right preferences and CRF Model file */
if(hasWorkspaceCookieId) {
String cachedWorkspaceId = request.getParameter(Arguments.workspacePreferencesId.name());
workspace = WorkspaceManager.getInstance().createWorkspaceWithPreferencesId(cachedWorkspaceId);
vwsp = new VWorkspace(workspace, cachedWorkspaceId);
} else {
workspace = WorkspaceManager.getInstance().createWorkspace();
vwsp = new VWorkspace(workspace);
}
workspace.setMetadataManager(metadataManager);
WorkspaceRegistry.getInstance().register(new ExecutionController(workspace));
VWorkspaceRegistry.getInstance().registerVWorkspace(workspace.getId(), vwsp);
logger.info("Start Metadata Setup");
try {
metadataManager.register(new SemanticTypeModelMetadata(workspace), updateContainer);
metadataManager.register(new OntologyMetadata(workspace), updateContainer);
metadataManager.register(new JSONModelsMetadata(workspace), updateContainer);
metadataManager.register(new PythonTransformationMetadata(workspace), updateContainer);
metadataManager.register(new GraphVizMetadata(workspace), updateContainer);
metadataManager.register(new ModelLearnerMetadata(workspace), updateContainer);
metadataManager.register(new R2RMLMetadata(workspace), updateContainer);
metadataManager.register(new R2RMLPublishedMetadata(workspace), updateContainer);
metadataManager.register(new RDFMetadata(workspace), updateContainer);
metadataManager.register(new CSVMetadata(workspace), updateContainer);
metadataManager.register(new JSONMetadata(workspace), updateContainer);
metadataManager.register(new ReportMetadata(workspace), updateContainer);
metadataManager.register(new AvroMetadata(workspace), updateContainer);
} catch (KarmaException e) {
logger.error("Unable to complete Karma set up: ", e);
}
CommandHistory.setIsHistoryEnabled(true);
CommandHistory.setHistorySaver(workspace.getId(), new R2RMLAlignmentFileSaver(workspace));
// Initialize the Outlier tag
Tag outlierTag = new Tag(TagName.Outlier, Color.Red);
workspace.getTagsContainer().addTag(outlierTag);
// Put all created worksheet models in the view.
updateContainer.add(new WorksheetListUpdate());
for (Worksheet w : vwsp.getWorkspace().getWorksheets()) {
updateContainer.append(WorksheetUpdateFactory.createWorksheetHierarchicalUpdates(w.getId(), SuperSelectionManager.DEFAULT_SELECTION));
}
updateContainer.add(new AbstractUpdate() {
@Override
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
//1. Load all configurations
UIConfiguration.Instance().loadConfig();
ModelingConfiguration.load();
//2 Return all settings related updates
pw.println("{");
pw.println("\"updateType\": \"UISettings\", ");
pw.println("\"settings\": {");
pw.println(" \"googleEarthEnabled\" : " + UIConfiguration.Instance().isGoogleEarthEnabled() + ",");
pw.println(" \"maxLoadedClasses\" : " + UIConfiguration.Instance().getMaxClassesToLoad() + ",");
pw.println(" \"maxLoadedProperties\" : " + UIConfiguration.Instance().getMaxPropertiesToLoad());
pw.println(" }");
pw.println("}");
}
});
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
updateContainer.applyUpdates(vwsp);
updateContainer.generateJson("", pw, vwsp);
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(sw.toString());
}