Commit 2aef7f82 authored by Jay Jay Billings's avatar Jay Jay Billings

Started updating the core to add in-project Item creation.

Signed-off-by: default avatarJay Jay Billings <billingsjj@ornl.gov>
parent 105e3479
......@@ -12,6 +12,7 @@ Export-Package: org.eclipse.ice.client.common,
org.eclipse.ice.iclient.uiwidgets
Import-Package: javax.ws.rs.core,
org.eclipse.core.expressions,
org.eclipse.core.resources,
org.eclipse.core.runtime;version="3.4.0",
org.eclipse.ice.core.iCore,
org.eclipse.ice.datastructures.ICEObject,
......
......@@ -19,6 +19,7 @@ import java.util.ArrayList;
import javax.ws.rs.core.MediaType;
import org.eclipse.ice.core.iCore.ICore;
import org.eclipse.core.resources.IProject;
import org.eclipse.ice.datastructures.ICEObject.ICEList;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
import org.eclipse.ice.datastructures.form.Form;
......@@ -59,12 +60,13 @@ import org.slf4j.LoggerFactory;
* @author Jay Jay Billings
*/
public class RemoteCoreProxy implements ICore {
/**
* Logger for handling event messages and other information.
*/
private static final Logger logger = LoggerFactory.getLogger(RemoteCoreProxy.class);
private static final Logger logger = LoggerFactory
.getLogger(RemoteCoreProxy.class);
/**
* <p>
* The hostname of the server to which the proxy is connected.
......@@ -130,7 +132,8 @@ public class RemoteCoreProxy implements ICore {
* connected or, if it is not connected, it returns null.
* </p>
*
* @return <p>
* @return
* <p>
* The hostname
* </p>
*/
......@@ -144,7 +147,8 @@ public class RemoteCoreProxy implements ICore {
* its connection or, if it is not connected, it returns -1.
* </p>
*
* @return <p>
* @return
* <p>
* The port number
* </p>
*/
......@@ -203,7 +207,8 @@ public class RemoteCoreProxy implements ICore {
* <p>
* The users' password.
* </p>
* @return <p>
* @return
* <p>
* The client id as specified by ICore.connect().
* </p>
*/
......@@ -211,8 +216,8 @@ public class RemoteCoreProxy implements ICore {
// Create a filter for the client that sets the authentication
// credentials
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(
username, password);
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(username,
password);
client.addFilter(authFilter);
// Connect as usual
......@@ -479,4 +484,12 @@ public class RemoteCoreProxy implements ICore {
// TODO Auto-generated method stub
return null;
}
@Override
public String createItem(String itemType, IProject project) {
// This operation is not supported by the remote core proxy and may
// never be. As far as I know, there is no way to remotely transfer
// IProject instances with using full Java IPC.
return null;
}
}
\ No newline at end of file
......@@ -23,6 +23,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.eclipse.core.resources.IProject;
import org.eclipse.ice.datastructures.ICEObject.ICEList;
import org.eclipse.ice.datastructures.ICEObject.Identifiable;
import org.eclipse.ice.datastructures.form.Form;
......@@ -125,6 +126,27 @@ public interface ICore {
*
* @param itemType
* The type of Item to create.
* @param project
* The workspace project where the Item should be created and
* persisted.
* @return The identification number given as a String of the newly created
* Item or -1 if it was unable to create the Item. It is safe to
* parse this string as an integer.
*/
public String createItem(String itemType, IProject project);
/**
* This operation is a utility operation that performs the same work as the
* two argument createItem, except it creates the Item in a default project
* space.
*
* This operation is mapped via JAX-RS to the web interface.
*
* Of historical note, this was the original implementation of this
* operation and project support was added nearly four years later.
*
* @param itemType
* The type of Item to create.
* @return The identification number given as a String of the newly created
* Item or -1 if it was unable to create the Item. It is safe to
* parse this string as an integer.
......@@ -135,8 +157,7 @@ public interface ICore {
public String createItem(String itemType);
/**
* This operation directs the ICore to permanently delete an Item. Again:
* this is permanent!
* This operation directs the ICore to *PERMANTENTLY* delete an Item.
*
* @param itemId
* The identification number of the Item that should be deleted
......@@ -289,8 +310,7 @@ public interface ICore {
* argument is null.
* @param itemType
* The type of Item to create.
* @return
* The identification number given as a String of the newly created
* @return The identification number given as a String of the newly created
* Item or -1 if it was unable to create the Item. It is safe to
* parse this string as an integer.
*/
......
......@@ -201,14 +201,13 @@ public class Core extends Application implements ICore {
/**
* This operation stops the Core.
*
*/
public void stop() {
// Update everything in the ItemManager that requires it
itemManager.persistItems();
}
/**
/*
* (non-Javadoc)
*
* @see ICore#getFileSystem(int uniqueClientID)
......@@ -218,7 +217,7 @@ public class Core extends Application implements ICore {
return new Form();
}
/**
/*
* (non-Javadoc)
*
* @see ICore#registerItem(ItemBuilder itemBuilder)
......@@ -236,7 +235,7 @@ public class Core extends Application implements ICore {
return;
}
/**
/*
* (non-Javadoc)
*
* @see ICore#registerCompositeItem(ICompositeItemBuilder builder)
......@@ -246,15 +245,15 @@ public class Core extends Application implements ICore {
// Register the builder with the ItemManager so long as it is not null
if (builder != null) {
logger.info("ICore Message: Composite Item "
+ builder.getItemName() + " registered with Core.");
logger.info("ICore Message: Composite Item " + builder.getItemName()
+ " registered with Core.");
itemManager.registerCompositeBuilder(builder);
}
return;
}
/**
/*
* (non-Javadoc)
*
* @see ICore#unregisterItem(ItemBuilder itemBuilder)
......@@ -263,26 +262,38 @@ public class Core extends Application implements ICore {
public void unregisterItem(ItemBuilder itemBuilder) {
}
/**
/*
* (non-Javadoc)
*
* @see ICore#createItem(String itemType)
*/
@Override
public String createItem(String itemType) {
return createItem(itemType, projectTable.get("defaultUser"));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.core.iCore.ICore#createItem(java.lang.String,
* org.eclipse.core.resources.IProject)
*/
public String createItem(String itemType, IProject project) {
// Local Declarations
int newItemId = -1;
// Create the Item if the ItemType is not null and the project space is
// available
if (itemType != null && projectTable.get("defaultUser") != null) {
newItemId = itemManager.createItem(itemType,
projectTable.get("defaultUser"));
if (itemType != null && project != null) {
newItemId = itemManager.createItem(itemType, project);
} else {
logger.error("Unable to create Item in the core! Type = " + itemType
+ " , project = " + project);
}
return String.valueOf(newItemId);
}
/**
......@@ -429,8 +440,8 @@ public class Core extends Application implements ICore {
IFile fileInProject = project.getFile(path.lastSegment());
// Get the paths and convert them to strings
IPath fullPathInProject = fileInProject.getLocation();
String path1 = path.toString(), path2 = fullPathInProject
.toString();
String path1 = path.toString(),
path2 = fullPathInProject.toString();
// Remove devices ids and other such things from the path strings
path1 = path1.substring(path1.lastIndexOf(":") + 1);
path2 = path2.substring(path2.lastIndexOf(":") + 1);
......@@ -446,15 +457,16 @@ public class Core extends Application implements ICore {
fileInProject.delete(true, null);
} catch (CoreException e) {
// Complain and don't do anything else.
logger.info("Core Message: " + "Unable to import file.");
logger.info(
"Core Message: " + "Unable to import file.");
logger.error(getClass().getName() + " Exception!", e);
return;
}
}
try {
// Open a stream of the file
FileInputStream fileStream = new FileInputStream(new File(
file));
FileInputStream fileStream = new FileInputStream(
new File(file));
// Import the file
fileInProject.create(fileStream, true, null);
} catch (FileNotFoundException e) {
......@@ -474,8 +486,8 @@ public class Core extends Application implements ICore {
// Drop some debug info.
if (System.getProperty("DebugICE") != null) {
logger.info("Core Message: " + "Imported file "
+ file.toString());
logger.info(
"Core Message: " + "Imported file " + file.toString());
}
}
......@@ -531,8 +543,8 @@ public class Core extends Application implements ICore {
// Grab PSF or XML file
if (filename.endsWith(".psf") | filename.endsWith(".xml")) {
// Get the file
file = project.getFile(currentResource
.getProjectRelativePath());
file = project.getFile(
currentResource.getProjectRelativePath());
try {
// Load the SerializedItemBuilder
builder = new SerializedItemBuilder(
......@@ -646,7 +658,9 @@ public class Core extends Application implements ICore {
/**
* This private operation configures the project area for the Core. It uses
* the Eclipse Resources Plugin and behaves differently based on the value
* of the osgi.instance.area system property. </p> <!-- end-UML-doc -->
* of the osgi.instance.area system property.
* </p>
* <!-- end-UML-doc -->
*
* @return True if the setup operation was successful and false otherwise.
*/
......@@ -847,9 +861,9 @@ public class Core extends Application implements ICore {
// Print the message if debugging is enabled
// if (debuggingEnabled) {
logger.info("Core Message: " + "Update received with message: "
+ message);
// }
logger.info(
"Core Message: " + "Update received with message: " + message);
// }
// Only process the message if it exists and is not empty
if (message != null && !message.isEmpty() && message.contains("=")) {
......@@ -858,7 +872,8 @@ public class Core extends Application implements ICore {
String[] messageParts = message.split("=");
if (messageParts.length > 1) {
// Get the message object.
ArrayList<Message> msgList = buildMessagesFromString(messageParts[1]);
ArrayList<Message> msgList = buildMessagesFromString(
messageParts[1]);
// Post the messages if there are any. Fail otherwise.
if (!msgList.isEmpty()) {
for (int i = 0; i < msgList.size(); i++) {
......@@ -874,4 +889,5 @@ public class Core extends Application implements ICore {
// Unlock the operation and return safely
return (updateLock.getAndSet(false)) ? retVal : null;
}
}
......@@ -26,6 +26,7 @@ import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.FormStatus;
import org.eclipse.ice.item.ICompositeItemBuilder;
import org.eclipse.ice.item.ItemBuilder;
import org.eclipse.core.resources.IProject;
/**
* <p>
......@@ -507,4 +508,10 @@ public class FakeCore implements ICore {
// TODO Auto-generated method stub
return null;
}
@Override
public String createItem(String itemType, IProject project) {
// TODO Auto-generated method stub
return null;
}
}
\ No newline at end of file
/bin
/target
/itemManagerTesterWorkspace
/default2/
......@@ -27,6 +27,7 @@ import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
......@@ -117,8 +118,10 @@ public class CoreTester {
for (int i = 0; !found && i < availableBuilders.size(); i++) {
found = testItemName.equals(availableBuilders.get(i));
}
assertTrue("ItemManagerTester: " + "FakeModuleBuilder with name "
+ testItemName + " not found in available builders!", found);
assertTrue(
"ItemManagerTester: " + "FakeModuleBuilder with name "
+ testItemName + " not found in available builders!",
found);
// Make sure the available builders includes the fake geometry builder.
found = false;
......@@ -126,8 +129,10 @@ public class CoreTester {
for (int i = 0; !found && i < availableBuilders.size(); i++) {
found = testItemName.equals(availableBuilders.get(i));
}
assertTrue("ItemManagerTester: " + "FakeGeometryBuilder with name "
+ testItemName + " not found in available builders!", found);
assertTrue(
"ItemManagerTester: " + "FakeGeometryBuilder with name "
+ testItemName + " not found in available builders!",
found);
// Register the CompositeItemBuilder
iCECore.registerCompositeItem(fakeCompositeBuilder);
......@@ -161,6 +166,7 @@ public class CoreTester {
// Local Declarations
FakeGeometryBuilder fakeGeometryBuilder = new FakeGeometryBuilder();
FakeModuleBuilder fakeModuleBuilder = new FakeModuleBuilder();
String name = fakeModuleBuilder.getItemName();
ArrayList<String> types = new ArrayList<String>();
// Check the available Item types before registration to make sure that
......@@ -177,8 +183,7 @@ public class CoreTester {
assertTrue(types.contains(fakeModuleBuilder.getItemName()));
// Create a new Item
int itemId = Integer.parseInt(iCECore.createItem(fakeModuleBuilder
.getItemName()));
int itemId = Integer.parseInt(iCECore.createItem(name));
// Check the Item id
assertNotNull(itemId);
......@@ -191,14 +196,10 @@ public class CoreTester {
// Create a few more and store the ids
ArrayList<Integer> ids = new ArrayList<Integer>();
ids.add(itemId);
ids.add(Integer.parseInt(iCECore.createItem(fakeModuleBuilder
.getItemName())));
ids.add(Integer.parseInt(iCECore.createItem(fakeModuleBuilder
.getItemName())));
ids.add(Integer.parseInt(iCECore.createItem(fakeModuleBuilder
.getItemName())));
ids.add(Integer.parseInt(iCECore.createItem(fakeModuleBuilder
.getItemName())));
ids.add(Integer.parseInt(iCECore.createItem(name)));
ids.add(Integer.parseInt(iCECore.createItem(name)));
ids.add(Integer.parseInt(iCECore.createItem(name)));
ids.add(Integer.parseInt(iCECore.createItem(name)));
// Get the list of ICEObjects that represents the Items that have been
// created and check it
......@@ -213,8 +214,8 @@ public class CoreTester {
}
// Make sure that there are no items
assertEquals(0, iCECore.getItemList().size());
System.out.println("Num ITEMS after delete = "
+ iCECore.getItemList().size());
System.out.println(
"Num ITEMS after delete = " + iCECore.getItemList().size());
return;
}
......@@ -246,8 +247,8 @@ public class CoreTester {
// This class has a special implementation of reviewEntries that
// makes testing easier. Adding two data components will make it pass
// its review, but adding any more will cause it to fail.
testItemId = Integer.parseInt(iCECore.createItem(fakeGeometryBuilder
.getItemName()));
testItemId = Integer.parseInt(
iCECore.createItem(fakeGeometryBuilder.getItemName()));
assertTrue(testItemId > 0);
// Get the Form and make sure it is not null
......@@ -302,38 +303,11 @@ public class CoreTester {
int testItemId = 0;
FakeGeometryBuilder fakeGeometryBuilder = new FakeGeometryBuilder();
FormStatus status = FormStatus.InfoError;
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
URI defaultProjectLocation = null;
IProject project = null;
String separator = System.getProperty("file.separator");
// Setup the project space so that the output file can be checked.
try {
// Get the project handle
project = workspaceRoot.getProject("itemManagerTesterWorkspace");
// If the project does not exist, create it
if (!project.exists()) {
// Set the location as ${workspace_loc}/ItemTesterWorkspace
defaultProjectLocation = (new File(
System.getProperty("user.dir") + separator
+ "itemManagerTesterWorkspace")).toURI();
// Create the project description
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription("itemManagerTesterWorkspace");
// Set the location of the project
desc.setLocationURI(defaultProjectLocation);
// Create the project
project.create(desc, null);
}
// Open the project if it is not already open
if (project.exists() && !project.isOpen()) {
project.open(null);
}
} catch (CoreException e) {
// Catch for creating the project
e.printStackTrace();
fail();
}
project = getProject("itemManagerTesterWorkspace");
// Register the ItemBuilders
iCECore.registerItem(fakeGeometryBuilder);
......@@ -346,8 +320,8 @@ public class CoreTester {
// This class has a special implementation of reviewEntries that
// makes testing easier. Adding two data components will make it pass
// its review, but adding any more will cause it to fail.
testItemId = Integer.parseInt(iCECore.createItem(fakeGeometryBuilder
.getItemName()));
testItemId = Integer.parseInt(
iCECore.createItem(fakeGeometryBuilder.getItemName()));
assertTrue(testItemId > 0);
// Direct the Core to process the Item
......@@ -363,10 +337,10 @@ public class CoreTester {
// Setup the name of the output file. According to the documentation it
// should be at <itemName>_<itemId>_processOutput.txt.
String outputFilename = fakeItem.getName().replaceAll("\\s+", "_")
+ "_" + fakeItem.getId() + "_processOutput.txt";
System.out
.println("CoreTester message: Looking for (shortened) output file name \""
String outputFilename = fakeItem.getName().replaceAll("\\s+", "_") + "_"
+ fakeItem.getId() + "_processOutput.txt";
System.out.println(
"CoreTester message: Looking for (shortened) output file name \""
+ outputFilename + "\"");
// Get the output file handle
File outputFile = iCECore.getItemOutputFile(testItemId);
......@@ -406,36 +380,9 @@ public class CoreTester {
int testItemId = 0;
Form testForm = null;
FakeGeometryBuilder fakeGeometryBuilder = new FakeGeometryBuilder();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
URI defaultProjectLocation = null;
IProject project = null;
String separator = System.getProperty("file.separator");
// Setup the project space so that the output file can be checked.
try {
// Get the project handle
project = workspaceRoot.getProject("default");
// If the project does not exist, create it
if (!project.exists()) {
// Create the project description
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription("default");
System.out.println("CoreTester Message: "
+ "Workspace location is " + desc.getComment());
// Set the location of the project
desc.setLocationURI(defaultProjectLocation);
// Create the project
project.create(desc, null);
}
// Open the project if it is not already open
if (project.exists() && !project.isOpen()) {
project.open(null);
}
} catch (CoreException e) {
// Catch for creating the project
e.printStackTrace();
fail();
}
project = getProject("default");
// Clean out any old test files
try {
......@@ -454,8 +401,8 @@ public class CoreTester {
assertNotNull(types);
// Create an Item
testItemId = Integer.parseInt(iCECore.createItem(fakeGeometryBuilder
.getItemName()));
testItemId = Integer.parseInt(
iCECore.createItem(fakeGeometryBuilder.getItemName()));
// Create a test file
File testFile = new File("testFile.test");
......@@ -515,11 +462,8 @@ public class CoreTester {
}
/**
* <p>
* This operation is responsible for testing the ability of the Core to post
* updates from the ICEUpdater.
* </p>
*
*/
@Test
public void checkRealtimeUpdates() {
......@@ -535,13 +479,11 @@ public class CoreTester {
iCECore.registerItem(fakeGeometryBuilder);
// Create an Item
int id = Integer.parseInt(iCECore.createItem(fakeGeometryBuilder
.getItemName()));
int id = Integer.parseInt(
iCECore.createItem(fakeGeometryBuilder.getItemName()));
// A message from some of the Updater tests
String msg = "post={\"item_id\":\""
+ id
+ "\", "
String msg = "post={\"item_id\":\"" + id + "\", "
+ "\"client_key\":\"1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ\", "
+ "\"posts\":[{\"type\":\"UPDATER_STARTED\",\"message\":\"\"},"
+ "{\"type\":\"FILE_MODIFIED\","
......@@ -578,10 +520,8 @@ public class CoreTester {
}
/**
* <p>
* checkConnection() checks Core's ability to make a client connection with
* This operation checks the Core's ability to make a client connection with
* a given username, password, and Client ID.
* </p>
*
*/
@Test
......@@ -594,4 +534,98 @@ public class CoreTester {
return;
}
/**
* This operation checks that the second create() operation functions
* properly.
*