Commits

Anonymous committed 6e77ab3

start with the channel admin

  • Participants
  • Parent commits 25db180

Comments (0)

Files changed (17)

File com.ibh.systems.repoman-product/RepoMan.launch

 <stringAttribute key="bootstrap" value=""/>
 <stringAttribute key="checked" value="[NONE]"/>
 <booleanAttribute key="clearConfig" value="true"/>
-<booleanAttribute key="clearws" value="false"/>
+<booleanAttribute key="clearws" value="true"/>
 <stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/RepoMan"/>
 <booleanAttribute key="default" value="true"/>
 <booleanAttribute key="default_auto_start" value="true"/>
 <booleanAttribute key="tracing" value="false"/>
 <booleanAttribute key="useCustomFeatures" value="false"/>
 <booleanAttribute key="useDefaultConfigArea" value="true"/>
-<stringAttribute key="workspace_bundles" value="com.ibh.systems.repoman.app@default:default,com.ibh.systems.repoman.channel.jpa@default:default,com.ibh.systems.repoman.channel@default:default,com.ibh.systems.repoman.servlet@default:default,com.ibh.systems.repoman.storage.file@default:default,com.ibh.systems.repoman.storage@default:default"/>
+<stringAttribute key="workspace_bundles" value="com.ibh.systems.repoman.app@default:default,com.ibh.systems.repoman.channel.jpa.service@default:default,com.ibh.systems.repoman.channel.jpa@default:default,com.ibh.systems.repoman.channel@default:default,com.ibh.systems.repoman.servlet@default:default,com.ibh.systems.repoman.storage.file@default:default,com.ibh.systems.repoman.storage@default:default"/>
 </launchConfiguration>

File com.ibh.systems.repoman.channel.jpa.service/.classpath

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

File com.ibh.systems.repoman.channel.jpa.service/.gitignore

+/bin

File com.ibh.systems.repoman.channel.jpa.service/.project

+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>com.ibh.systems.repoman.channel.jpa.service</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ds.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File com.ibh.systems.repoman.channel.jpa.service/.settings/org.eclipse.jdt.core.prefs

+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

File com.ibh.systems.repoman.channel.jpa.service/.settings/org.eclipse.pde.core.prefs

+eclipse.preferences.version=1
+pluginProject.equinox=false
+pluginProject.extensions=false
+resolve.requirebundle=false

File com.ibh.systems.repoman.channel.jpa.service/META-INF/MANIFEST.MF

+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: JPA Channel Service
+Bundle-SymbolicName: com.ibh.systems.repoman.channel.jpa.service
+Bundle-Version: 0.1.0.qualifier
+Bundle-Vendor: IBH SYSTEMS GmbH
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: com.ibh.systems.repoman.channel;version="0.1.0",
+ com.ibh.systems.repoman.channel.jpa;version="0.1.0",
+ javax.persistence;version="2.1.0",
+ javax.persistence.criteria;version="2.1.0",
+ org.osgi.service.event;version="1.3.0"
+Service-Component: OSGI-INF/*.xml

File com.ibh.systems.repoman.channel.jpa.service/OSGI-INF/service.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.ibh.systems.repoman.channel.jpa.service">
+   <implementation class="com.ibh.systems.repoman.channel.jpa.service.ChannelManagerImpl"/>
+   <reference bind="setEmf" cardinality="1..1" interface="javax.persistence.EntityManagerFactory" name="EntityManagerFactory" policy="static" target="(osgi.unit.name=com.ibh.systems.repoman.channel.jpa)"/>
+   <service>
+      <provide interface="com.ibh.systems.repoman.channel.ChannelManager"/>
+   </service>
+   <reference bind="setEventAdmin" cardinality="0..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" policy="static"/>
+</scr:component>

File com.ibh.systems.repoman.channel.jpa.service/build.properties

+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               OSGI-INF/,\
+               OSGI-INF/service.xml
+source.. = src/

File com.ibh.systems.repoman.channel.jpa.service/src/com/ibh/systems/repoman/channel/jpa/service/ChannelManagerImpl.java

+package com.ibh.systems.repoman.channel.jpa.service;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.Event;
+
+import com.ibh.systems.repoman.channel.Artifact;
+import com.ibh.systems.repoman.channel.Channel;
+import com.ibh.systems.repoman.channel.ChannelManager;
+
+public class ChannelManagerImpl implements ChannelManager {
+
+	private class ChannelImpl implements Channel {
+		private String id;
+
+		public ChannelImpl(com.ibh.systems.repoman.channel.jpa.Channel input) {
+			this.id = input.getId();
+		}
+
+		@Override
+		public String getId() {
+			return id;
+		}
+
+		@Override
+		public Collection<Artifact> getArtifacts() {
+			return Collections.emptyList();
+		}
+
+		@Override
+		public Artifact storeArtifact(InputStream stream) {
+			return null;
+		}
+
+		@Override
+		public void delete() {
+			ChannelManagerImpl.this.deleteChannel(id);
+		}
+	}
+
+	private EventAdmin eventAdmin;
+
+	public void setEventAdmin(EventAdmin eventAdmin) {
+		this.eventAdmin = eventAdmin;
+	}
+
+	private EntityManagerFactory emf;
+
+	public void setEmf(EntityManagerFactory emf) {
+		this.emf = emf;
+	}
+
+	public void deleteChannel(String id) {
+		EntityManager em = emf.createEntityManager();
+		try {
+			em.getTransaction().begin();
+			try {
+				com.ibh.systems.repoman.channel.jpa.Channel ref = em
+						.getReference(
+								com.ibh.systems.repoman.channel.jpa.Channel.class,
+								id);
+				em.remove(ref);
+				em.flush();
+				em.getTransaction().commit();
+				postEntityChange(id, "delete");
+			} catch (Exception e) {
+				em.getTransaction().rollback();
+				throw new RuntimeException (e);
+			}
+
+		} finally {
+			em.close();
+		}
+	}
+
+	private void postEntityChange(String id, String operation) {
+		if ( eventAdmin == null )
+			return;
+		
+		HashMap<String, String> properties = new HashMap<String, String>();
+		properties.put("id", id);
+		properties.put("operation", operation);
+	
+		eventAdmin.postEvent(new Event("entity/channel", properties));
+	}
+
+	@Override
+	public Collection<Channel> getChannels() {
+		EntityManager em = emf.createEntityManager();
+		try {
+			CriteriaBuilder cb = emf.getCriteriaBuilder();
+			CriteriaQuery<com.ibh.systems.repoman.channel.jpa.Channel> cq = cb
+					.createQuery(com.ibh.systems.repoman.channel.jpa.Channel.class);
+
+			TypedQuery<com.ibh.systems.repoman.channel.jpa.Channel> query = em
+					.createQuery(cq);
+			return convert(query.getResultList());
+		} finally {
+			em.close();
+		}
+	}
+
+	private Collection<Channel> convert(
+			List<com.ibh.systems.repoman.channel.jpa.Channel> resultList) {
+		Collection<Channel> result = new ArrayList<Channel>(resultList.size());
+
+		for (com.ibh.systems.repoman.channel.jpa.Channel input : resultList) {
+			Channel output = new ChannelImpl(input);
+			result.add(output);
+		}
+
+		return result;
+	}
+
+	@Override
+	public Channel getChannel(String id) {
+		EntityManager em = emf.createEntityManager();
+		try {
+			com.ibh.systems.repoman.channel.jpa.Channel channel = em.find(
+					com.ibh.systems.repoman.channel.jpa.Channel.class, id);
+			if (channel != null)
+				return new ChannelImpl(channel);
+			else
+				return null;
+
+		} finally {
+			em.close();
+		}
+	}
+
+	@Override
+	public Channel createChannel(String id) {
+		EntityManager em = emf.createEntityManager();
+		try {
+			com.ibh.systems.repoman.channel.jpa.Channel channel;
+			em.getTransaction().begin();
+			try {
+				channel = new com.ibh.systems.repoman.channel.jpa.Channel();
+				channel.setId(id);
+				em.persist(channel);
+				em.flush();
+				em.getTransaction().commit();
+			} catch (Exception e) {
+				em.getTransaction().rollback();
+				throw new RuntimeException(e);
+			}
+			postEntityChange(id, "create");
+			return new ChannelImpl(channel);
+		} finally {
+			em.close();
+		}
+	}
+
+}

File com.ibh.systems.repoman.channel.jpa/META-INF/MANIFEST.MF

 Bundle-SymbolicName: com.ibh.systems.repoman.channel.jpa
 Bundle-Version: 0.1.0.qualifier
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: javax.persistence;version="2.1.0"
+Import-Package: javax.persistence;version="2.1.0",
+ javax.persistence.metamodel;version="2.1.0"
 Meta-Persistence: META-INF/persistence.xml
+Export-Package: com.ibh.systems.repoman.channel.jpa;version="0.1.0"

File com.ibh.systems.repoman.channel.jpa/META-INF/persistence.xml

 	<persistence-unit name="com.ibh.systems.repoman.channel.jpa" transaction-type="RESOURCE_LOCAL">
 		<class>com.ibh.systems.repoman.channel.jpa.Channel</class>
 		<properties>
-			<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:repoman"/>
+			<property name="javax.persistence.jdbc.url" value="jdbc:h2:repoman"/>
 			<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
-			<property name="javax.persistence.schema-generation.create-database-schemas" value="true"/>
-			<property name="javax.persistence.schema-generation.database.action" value="create"/>
+			<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
+			<property name="eclipselink.ddl-generation.output-mode" value="database"/>
+			<property name="eclipselink.weaving" value="false"/>
 		</properties>
 	</persistence-unit>
 </persistence>

File com.ibh.systems.repoman.channel/.project

 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ds.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>

File com.ibh.systems.repoman.channel/META-INF/MANIFEST.MF

 Bundle-Version: 0.1.0.qualifier
 Bundle-Vendor: IBH SYSTEMS GmbH
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: com.ibh.systems.repoman.channel;version="0.1.0"
+Service-Component: OSGI-INF/console.xml

File com.ibh.systems.repoman.channel/OSGI-INF/console.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.ibh.systems.repoman.channel.console">
+   <implementation class="com.ibh.systems.repoman.channel.console.ConsoleImpl"/>
+   <property name="osgi.command.scope" type="String" value="channel"/>
+   <property name="osgi.command.function" type="String">list
+add
+delete
+   </property>
+   <service>
+      <provide interface="com.ibh.systems.repoman.channel.console.ConsoleImpl"/>
+   </service>
+   <reference bind="setChannelManager" cardinality="1..1" interface="com.ibh.systems.repoman.channel.ChannelManager" name="ChannelManager" policy="static"/>
+</scr:component>

File com.ibh.systems.repoman.channel/build.properties

-source.. = src/
 output.. = bin/
 bin.includes = META-INF/,\
-               .
+               .,\
+               OSGI-INF/
+source.. = src/

File com.ibh.systems.repoman.channel/src/com/ibh/systems/repoman/channel/console/ConsoleImpl.java

+package com.ibh.systems.repoman.channel.console;
+
+import com.ibh.systems.repoman.channel.Channel;
+import com.ibh.systems.repoman.channel.ChannelManager;
+
+public class ConsoleImpl {
+	
+	private ChannelManager channelManager;
+	
+	public void setChannelManager(ChannelManager channelManager) {
+		this.channelManager = channelManager;
+	}
+	
+	public void list ()
+	{
+		System.out.println("Channels:");
+		for ( Channel channel : channelManager.getChannels() )
+		{
+			System.out.println("  " + channel.getId());
+		}
+	}
+	
+	public void add ( String channelId )
+	{
+		channelManager.createChannel(channelId);
+	}
+	
+	public void delete ( String channelId )
+	{
+		Channel channel = channelManager.getChannel(channelId);
+		if ( channel != null )
+		{
+			System.out.println("Deleted channel: " + channelId);
+			channel.delete();
+		}
+		else
+		{
+			System.err.println("Channel not found:" + channelId);
+		}
+	}
+}