Commit 30d97973 authored by Constantin Jucovschi's avatar Constantin Jucovschi
Browse files

initial commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
target/
bin/
*~
*.log
felix-cache
.metadata
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>deepamehta</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this
work for additional information regarding copyright ownership. The ASF licenses
this file to You under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You may obtain
a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
<artifactId>deepamehta</artifactId>
<version>${sally4.version}</version>
<parent>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4</artifactId>
<version>1.0</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.annotations</artifactId>
<version>1.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-utils</artifactId>
<version>${sally4.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-docmanager</artifactId>
<version>${sally4.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4.comm</groupId>
<artifactId>comm-annotation</artifactId>
<version>${sally4.version}</version>
</dependency>
<dependency>
<groupId>info.kwarc.sally4</groupId>
<artifactId>sally4-servlet</artifactId>
<version>${sally4.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- BND Maven Plugin Configuration -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>info.kwarc.sally4.deepamehta.impl*</Private-Package>
<Export-Package>info.kwarc.sally4.deepamehta*;libs*</Export-Package>
</instructions>
</configuration>
</plugin>
<!-- iPOJO Maven Plugin Configuration : nothing to do -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-ipojo-plugin</artifactId>
<version>1.11.2</version>
<executions>
<execution>
<goals>
<goal>ipojo-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package info.kwarc.sally4.deepamehta;
public interface Annotator {
void navigateTo(String URI);
}
package info.kwarc.sally4.deepamehta;
public interface DeepaMehta {
}
package info.kwarc.sally4.deepamehta.factories;
import info.kwarc.sally4.docmanager.SallyDoc;
import java.util.Dictionary;
import java.util.Hashtable;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.InstanceStateListener;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Instantiate
public class AnnotatorFactory {
@Requires(filter="(factory.name=info.kwarc.sally4.deepamehta.impl.AnnotatorInstance)")
Factory annotFactory;
Logger log;
public AnnotatorFactory() {
log = LoggerFactory.getLogger(getClass());
}
final String[] req = {"select", "theo"};
void addDoc(SallyDoc doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
if (!doc.supports("annotated_doc")) {
return;
}
createInstance(annotFactory, "Annotation ", doc.getDocQueue());
}
void createInstance(Factory factory, String name, String docQueue) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
Dictionary<String, Object> filters = new Hashtable<String, Object>();
filters.put("docQueue", "(docQueue="+docQueue+")");
configuration.put("requires.filters", filters);
configuration.put("instance.name", name+" for doc:"+docQueue);
ComponentInstance inst = factory.createComponentInstance(configuration);
inst.addInstanceStateListener(new InstanceStateListener() {
@Override
public void stateChanged(ComponentInstance arg0, int arg1) {
if (arg1 == ComponentInstance.INVALID) {
arg0.dispose();
}
}
});
}
public static <T> boolean contains( final T[] array, final T v ) {
for ( final T e : array )
if ( e == v || v != null && v.equals( e ) )
return true;
return false;
}
@Bind(aggregate=true)
void newSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
addDoc(newDoc);
}
@Unbind(aggregate=true)
void removeSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
//removeDoc(newDoc);
}
}
package info.kwarc.sally4.deepamehta.factories;
import info.kwarc.sally4.docmanager.SallyDoc;
import java.util.Dictionary;
import java.util.Hashtable;
import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.InstanceStateListener;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Unbind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Instantiate
public class DeepaMehtaFactory {
@Requires(filter="(factory.name=info.kwarc.sally4.deepamehta.impl.DeepaMehtaInstance)")
Factory deepaFactory;
Logger log;
public DeepaMehtaFactory() {
log = LoggerFactory.getLogger(getClass());
}
final String[] req = {"select", "theo"};
void addDoc(SallyDoc doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
if (!doc.supports("deepa")) {
return;
}
createInstance(deepaFactory, "Deepa ", doc.getDocQueue());
}
void createInstance(Factory factory, String name, String docQueue) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
Dictionary<String, Object> filters = new Hashtable<String, Object>();
filters.put("docQueue", "(docQueue="+docQueue+")");
configuration.put("requires.filters", filters);
configuration.put("instance.name", name+" for doc:"+docQueue);
ComponentInstance inst = factory.createComponentInstance(configuration);
inst.addInstanceStateListener(new InstanceStateListener() {
@Override
public void stateChanged(ComponentInstance arg0, int arg1) {
if (arg1 == ComponentInstance.INVALID) {
arg0.dispose();
}
}
});
}
public static <T> boolean contains( final T[] array, final T v ) {
for ( final T e : array )
if ( e == v || v != null && v.equals( e ) )
return true;
return false;
}
@Bind(aggregate=true)
void newSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
addDoc(newDoc);
}
@Unbind(aggregate=true)
void removeSallyDoc(SallyDoc newDoc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
//removeDoc(newDoc);
}
}
package info.kwarc.sally4.deepamehta.impl;
import info.kwarc.sally.comm.annotation.NavigateTo;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.deepamehta.Annotator;
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.marshalling.CommUtils;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
@Component
@Provides(specifications=Annotator.class)
public class AnnotatorInstance extends RouteBuilder implements Annotator{
@Requires(id="docQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc annotRoute;
@Requires
CamelContextProvider camelContextProvider;
CamelContext context;
@Validate
void doStart() throws Exception {
log.info(">>>>Starting Annotator");
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addComponent("annot", annotRoute.getAlexComponent());
context.addRoutes(this);
context.start();
}
@Invalidate
void doStop() throws Exception {
context.stop();
}
public AnnotatorInstance() {
}
@Override
public void configure() throws Exception {
DataFormat annotation = CommUtils.getDataFormat("annotation", getClass().getClassLoader());
from("direct:sendMsgEvent")
.marshal(annotation)
.inOnly("annot:default");
}
@Override
public void navigateTo(String URI) {
NavigateTo nav = new NavigateTo();
nav.setId(URI);
getContext().createProducerTemplate().sendBody("direct:sendMsgEvent", nav);
}
}
package info.kwarc.sally4.deepamehta.impl;
import info.kwarc.sally.comm.annotation.NavigateTo;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.deepamehta.Annotator;
import info.kwarc.sally4.deepamehta.DeepaMehta;
import info.kwarc.sally4.docmanager.IActionAcceptor;
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.marshalling.CommUtils;
import info.kwarc.sally4.predicates.BodyHasType;
import info.kwarc.sally4.predicates.XMLMessageNamespace;
import info.kwarc.sally4.processors.TypedCallback;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
@Component
@Provides(specifications=DeepaMehta.class)
public class DeepaMehtaInstance extends RouteBuilder implements DeepaMehta, TypedCallback<IActionAcceptor>{
@Requires(id="docQueue", filter="(filterThatWillNeverSucceed=1)")
SallyDoc deepaRoute;
@Requires
Annotator [] annotators;
@Requires
CamelContextProvider camelContextProvider;
CamelContext context;
@Validate
void doStart() throws Exception {
log.info(">>>>Starting DeepaInstance");
deepaRoute.addMessageHandler(this);
context = new DefaultCamelContext();
context.addComponent("activemq", camelContextProvider.getComponent("activemq"));
context.addComponent("alex", deepaRoute.getAlexComponent());
context.addRoutes(this);
context.start();
}
@Invalidate
void doStop() throws Exception {
context.stop();
}
public DeepaMehtaInstance() {
}
@Override
public void configure() throws Exception {
DataFormat annotation = CommUtils.getDataFormat("annotation", getClass().getClassLoader());
from("direct:getMessage")
.to("log:DeepaMehtaInstance")
.choice()
.when(new XMLMessageNamespace("annotation"))
.unmarshal(annotation)
.choice()
.when(new BodyHasType(NavigateTo.class))
.bean(method(this, "doProcess"))
.otherwise()
.stop()
.endChoice();
}
public void doProcess(NavigateTo navRequest) {
for (Annotator a : annotators) {
a.navigateTo(navRequest.getId());
}
}
@Override
public boolean run(IActionAcceptor obj) {
log.info("Deepa Received Message");
getContext().createProducerTemplate().send("direct:getMessage", obj.cloneExchange());
return true;
}
}
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://kwarc.info/sally/comm/select">
<xs:element name="onsallyframe">
<xs:complexType>
<xs:sequence>
<xs:element name="posx" type="xs:int" />
<xs:element name="posy" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://kwarc.info/sally/comm/spreadsheet" elementFormDefault="qualified">
<xs:element name="range">
<xs:complexType>
<xs:sequence>
<xs:element name="sheet" type="xs:string"/>
<xs:element name="startrow" type="xs:int"></xs:element>
<xs:element name="endrow" type="xs:int"></xs:element>
<xs:element name="startcol" type="xs:int"></xs:element>
<xs:element name="endcol" type="xs:int"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
<html>
<script type="text/javascript" src=""></script>
<script src='/sally/jobad/libs/js/libs.js'></script>
<link rel='stylesheet' type='text/css' href='/sally/jobad/libs/css/libs.css'>
<script src='/sally/jobad/JOBAD.min.js'></script>
<link rel='stylesheet' type='text/css' href='/sally/jobad/JOBAD.min.css'>
<body class="bootstrap">
<div class="navbar navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="#">MathHub Workers</a>
</div>
</div>
<#list body.env?keys as e>
<form action="setmhw">
<div class="row-fluid">
<div class="span1">${e_index+1}.</div>
<button class="span11 btn">
${body.env[e].getDescription()}
</button>
<input type="hidden" name="envid" value="${e}" />
<input type="hidden" name="id" value="${body.doc_queue_id}" />
</div>
</form>
</#list>
</body>
</html>
\ No newline at end of file
package info.kwarc.sally4.mathhubworker.impl;
/*
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.docmanager.impl.SallyDocImpl;
import info.kwarc.sally4.docmanager.mocks.MockDocumentManager;
import info.kwarc.sally4.docmanager.mocks.MockGlobalContextProvider;
import info.kwarc.sally4.mathhubworker.routes.LMHWorkflowInstance;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;