Commit bc542593 authored by amccaskey's avatar amccaskey
Browse files

Adding new importFile and importFileAsItem methods to ICore and Core.



Added new methods to import files to specific projects. Tests updated in
CoreTester.checkFileImports
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent 8b75e0be
......@@ -520,4 +520,34 @@ public class FakeCore implements ICore {
public boolean wasLoaded() {
return loaded;
}
@Override
public String importFileAsItem(URI file, String itemType, IProject project) {
// TODO Auto-generated method stub
return null;
}
@Override
public String importFileAsItem(IFile file, String itemType) {
// TODO Auto-generated method stub
return null;
}
@Override
public String importFileAsItem(URI file, String itemType, String projectName) {
// TODO Auto-generated method stub
return null;
}
@Override
public void importFile(URI file, IProject project) {
// TODO Auto-generated method stub
}
@Override
public void importFile(URI file, String projectName) {
// TODO Auto-generated method stub
}
}
\ No newline at end of file
......@@ -856,15 +856,14 @@ public class ICEFormEditor extends SharedHeaderFormEditor
// Set the site
setSite(site);
// Set the input
setInput(input);
// Grab the form from the input or the client depending on the type of
// the input. This should only be a temporary switch until we remove the
// ICEFormInput and redirect the way the client works.
if (input instanceof ICEFormInput) {
ICEFormInput = (ICEFormInput) input;
iceDataForm = ICEFormInput.getForm();
// Set the input
setInput(input);
} else if (input instanceof FileEditorInput) {
// Grab the file and load the form
IFile formFile = ((FileEditorInput) input).getFile();
......@@ -872,6 +871,9 @@ public class ICEFormEditor extends SharedHeaderFormEditor
IClient client = IClient.getClient();
iceDataForm = client.loadItem(formFile);
logger.info("IClient and Form loaded.");
// Set *correct* input via a little short circuit.
ICEFormInput = new ICEFormInput(iceDataForm);
setInput(ICEFormInput);
} catch (CoreException e) {
// Complain
logger.error("Unable to get IClient instance!", e);
......
......@@ -87,6 +87,10 @@ public class ImportFileWizardPage extends WizardPage {
super(pageName);
// Get the extension registry and retrieve the client.
// FIXME IClient.getClient()
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry
.getExtensionPoint("org.eclipse.ice.client.clientInstance");
......
......@@ -7,8 +7,7 @@
*
* Contributors:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey
*******************************************************************************/
package org.eclipse.ice.client.common.wizards;
......@@ -31,7 +30,7 @@ import org.eclipse.ui.IWorkbenchWindow;
* it to the workbench import wizards).
* </p>
*
* @author Jay Jay Billings, Jordan
* @author Jay Jay Billings, Jordan Deyton, Alex McCaskey
*
*/
public class ImportItemWizard extends ImportFileWizard {
......@@ -55,6 +54,8 @@ public class ImportItemWizard extends ImportFileWizard {
super(window);
}
// FIXME init() get project if necessary
/*
* (non-Javadoc)
*
......
......@@ -488,4 +488,34 @@ public class RemoteCoreProxy implements ICore {
// TODO Auto-generated method stub
return null;
}
@Override
public String importFileAsItem(URI file, String itemType, IProject project) {
// TODO Auto-generated method stub
return null;
}
@Override
public String importFileAsItem(IFile file, String itemType) {
// TODO Auto-generated method stub
return null;
}
@Override
public String importFileAsItem(URI file, String itemType, String projectName) {
// TODO Auto-generated method stub
return null;
}
@Override
public void importFile(URI file, IProject project) {
// TODO Auto-generated method stub
}
@Override
public void importFile(URI file, String projectName) {
// TODO Auto-generated method stub
}
}
\ No newline at end of file
......@@ -128,10 +128,8 @@ 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;
......@@ -139,10 +137,8 @@ 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);
......@@ -223,15 +219,13 @@ 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;
}
/**
* This operation checks the ability of the core to load a single
* Item.
* This operation checks the ability of the core to load a single Item.
*/
@Test
public void checkSingleItemLoad() {
......@@ -252,7 +246,7 @@ public class CoreTester {
return;
}
/**
* This operation checks the Core by ensuring that Items can be updated.
*/
......@@ -277,8 +271,7 @@ 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
......@@ -347,8 +340,7 @@ 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
......@@ -364,11 +356,9 @@ 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 \""
+ outputFilename + "\"");
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);
// Make sure it is not null
......@@ -377,15 +367,13 @@ public class CoreTester {
// the file is stored, as long as the name is properly set for now. That
// means that the Item has created the file handle per the spec.
String retOutputName = outputFile.getAbsolutePath();
System.out.println("CoreTester message: Returned Output File Name = "
+ retOutputName);
System.out.println("CoreTester message: Returned Output File Name = " + retOutputName);
assertTrue(outputFile.getAbsolutePath().contains(outputFilename));
// Check canceling by putting the fake item into a persistent
// "Processing" state and shutting it down.
fakeItemManager.processItem(fakeItem.getId(), "setProcessing");
status = fakeItemManager.cancelItemProcess(fakeItem.getId(),
"setProcessing");
status = fakeItemManager.cancelItemProcess(fakeItem.getId(), "setProcessing");
assertTrue(fakeItem.wasCancelled());
assertEquals(FormStatus.ReadyToProcess, status);
......@@ -425,13 +413,14 @@ 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");
File testFile2 = new File("testFile2.test");
try {
testFile.createNewFile();
testFile2.createNewFile();
} catch (IOException e) {
// Complain
e.printStackTrace();
......@@ -445,6 +434,18 @@ public class CoreTester {
IFile testProjectFile = project.getFile("testFile.test");
assertTrue(testProjectFile.exists());
// Check that we can import a file to a given IProject
IProject testProject = getProject("testProject");
iCECore.importFile(testProjectFile.getLocationURI(), testProject);
IFile anotherTestProjectFile = testProject.getFile("testFile.test");
assertTrue(anotherTestProjectFile.exists());
// Check we can use the import method with project string name
iCECore.importFile(testFile2.toURI(), "testProject");
IFile test2 = testProject.getFile("testFile2.test");
assertTrue(test2.exists());
// Check the import in the fake item
FakeItem fakeItem = fakeGeometryBuilder.getLastFakeItem();
assertTrue(fakeItem.wasRefreshed());
......@@ -452,6 +453,8 @@ public class CoreTester {
// Delete the file from the project
try {
testProjectFile.delete(true, null);
anotherTestProjectFile.delete(true, null);
test2.delete(true, null);
} catch (CoreException e) {
// Complain
e.printStackTrace();
......@@ -459,8 +462,7 @@ public class CoreTester {
}
// Import the file as an input file
int itemId = Integer.valueOf(iCECore.importFileAsItem(testFile.toURI(),
fakeGeometryBuilder.getItemName()));
int itemId = Integer.valueOf(iCECore.importFileAsItem(testFile.toURI(), fakeGeometryBuilder.getItemName()));
// Check the id
assertTrue(itemId > 0);
......@@ -472,10 +474,37 @@ public class CoreTester {
testProjectFile = project.getFile("testFile.test");
assertTrue(testProjectFile.exists());
// Check that we can import as Item with an IFile
iCECore.importFile(testFile.toURI());
itemId = Integer
.valueOf(iCECore.importFileAsItem(project.getFile("testFile.test"), fakeGeometryBuilder.getItemName()));
assertTrue(itemId > 0);
// Check we can import an Item to a given IProject
itemId = Integer
.valueOf(iCECore.importFileAsItem(testFile.toURI(), fakeGeometryBuilder.getItemName(), testProject));
assertTrue(itemId > 0 && testProject.getFile("testFile.test").exists());
// Delete the file from the project
try {
testProject.getFile("testFile.test").delete(true, null);
} catch (CoreException e) {
// Complain
e.printStackTrace();
fail();
}
// Now make sure we can import as Item to a Project with given name
itemId = Integer
.valueOf(iCECore.importFileAsItem(testFile.toURI(), fakeGeometryBuilder.getItemName(), "testProject"));
assertTrue(itemId > 0 && testProject.getFile("testFile.test").exists());
// Delete the file from the project and the local directory
testFile.delete();
testFile2.delete();
try {
testProjectFile.delete(true, null);
testProject.delete(true, null);
} catch (CoreException e) {
// Complain
e.printStackTrace();
......@@ -499,14 +528,12 @@ 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 + "\", "
+ "\"client_key\":\"1234567890ABCDEFGHIJ1234567890ABCDEFGHIJ\", "
+ "\"posts\":[{\"type\":\"UPDATER_STARTED\",\"message\":\"\"},"
+ "{\"type\":\"FILE_MODIFIED\","
+ "\"posts\":[{\"type\":\"UPDATER_STARTED\",\"message\":\"\"}," + "{\"type\":\"FILE_MODIFIED\","
+ "\"message\":\"/tmp/file\"}]}";
// Make sure posting a valid message works
......@@ -604,24 +631,19 @@ public class CoreTester {
String separator = System.getProperty("file.separator");
// Setup the project space so that the output file can be checked.
System.out.println(
"CoreTester Workspace Root = " + workspaceRoot.getLocation());
System.out.println("CoreTester Workspace Root = " + workspaceRoot.getLocation());
System.out.println("Constructing project " + name);
try {
// Get the project handle
project = workspaceRoot.getProject(name);
// If the project does not exist, create it
if (!project.exists()) {
defaultProjectLocation = (new File(
System.getProperty("user.dir") + separator + name))
.toURI();
defaultProjectLocation = (new File(System.getProperty("user.dir") + separator + name)).toURI();
// Create the project description
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(name);
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(name);
// Set the location of the project
desc.setLocationURI(defaultProjectLocation);
System.out.println("CoreTester Message: "
+ "Project location is " + desc.getLocationURI());
System.out.println("CoreTester Message: " + "Project location is " + desc.getLocationURI());
// Create the project
project.create(desc, null);
}
......
......@@ -319,7 +319,82 @@ public interface ICore {
* parse this string as an integer.
*/
public String importFileAsItem(URI file, String itemType);
/**
* This operation directs the core to import a file into the specified IProject
* instance and load that file as an input for the specified Item type. It returns the id
* of the newly created Item.
*
* @param file
* The file that should be imported. Nothing will happen if this
* argument is null.
* @param itemType
* The type of Item to create.
* @param project
* The project instance this file will be imported into.
* @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 importFileAsItem(URI file, String itemType, IProject project);
/**
* This operation directs the core to import an IFile instance into its corresponding IProject
* instance and load that file as an input for the specified Item type. It returns the id
* of the newly created Item.
*
* @param file
* The file that should be imported. Nothing will happen if this
* argument is null. The IProject instance will be determined from
* this IFile instance.
* @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.
*/
public String importFileAsItem(IFile file, String itemType);
/**
* This operation directs the core to import a file into the specified IProject
* instance corresponding to the String projectName, and load that file as an
* input for the specified Item type. It returns the id of the newly created Item.
*
* @param file
* The file that should be imported. Nothing will happen if this
* argument is null.
* @param itemType
* The type of Item to create.
* @param projectName
* The name of the project instance this file will be imported into.
* @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 importFileAsItem(URI file, String itemType, String projectName);
/**
* This operation directs the core to import a file into the specified IProject instance.
*
* @param file
* The file that should be imported. Nothing will happen if this
* argument is null.
* @param project
* The IProject instance this file will be imported into.
*/
public void importFile(URI file, IProject project);
/**
* This operation directs the core to import a file into the specified IProject String name.
*
* @param file
* The file that should be imported. Nothing will happen if this
* argument is null.
* @param projectName
* The name of the IProject instance this file will be imported into.
*/
public void importFile(URI file, String projectName);
/**
* This operation posts a message containing an update to the ICE Item
* designated in the body of the message.
......@@ -340,4 +415,12 @@ public interface ICore {
@Consumes("application/x-www-form-urlencoded")
@Produces("text/plain")
public String postUpdateMessage(String message);
// NEED TO ADD
// importFile(URI) calls next one with default
// importFile(URI, IProject)
// importFile(URI, String projectName)
//
}
\ No newline at end of file
......@@ -166,8 +166,7 @@ public class Core extends Application implements ICore, BundleActivator {
// Set the project location
if (!setupProjectLocation()) {
throw new RuntimeException(
"ICore Message: Unable to load workspace!");
throw new RuntimeException("ICore Message: Unable to load workspace!");
}
// Set the update lock
......@@ -188,8 +187,7 @@ public class Core extends Application implements ICore, BundleActivator {
// Set the project location
if (!setupProjectLocation()) {
throw new RuntimeException(
"ICore Message: Unable to load workspace!");
throw new RuntimeException("ICore Message: Unable to load workspace!");
}
// Set the update lock
......@@ -215,8 +213,7 @@ public class Core extends Application implements ICore, BundleActivator {
// If the project does not exist, create it
if (!itemDBProject.exists()) {
// Create the project description
IProjectDescription desc = ResourcesPlugin.getWorkspace()
.newProjectDescription(projectName);
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName);
// Create the project
itemDBProject.create(desc, null);
}
......@@ -265,16 +262,14 @@ public class Core extends Application implements ICore, BundleActivator {
// Load up the ItemBuilders
ItemBuilder builder = null;
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(builderID);
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(builderID);
// If the point is available, create all the builders and load them into
// the Item Manager.
if (point != null) {
IConfigurationElement[] elements = point.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
builder = (ItemBuilder) elements[i]
.createExecutableExtension("class");
builder = (ItemBuilder) elements[i].createExecutableExtension("class");
// Register the builder
registerItem(builder);
}
......@@ -327,10 +322,8 @@ public class Core extends Application implements ICore, BundleActivator {
extensionPoints.add("org.eclipse.ice.core.persistenceProvider");
extensionPoints.add("org.eclipse.ice.datastructures.jaxbClassProvider");
for (String extensionPointName : extensionPoints) {
IExtensionPoint point = Platform.getExtensionRegistry()
.getExtensionPoint(extensionPointName);
logger.debug(
"##### Extensions for: " + extensionPointName + " #####");
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(extensionPointName);
logger.debug("##### Extensions for: " + extensionPointName + " #####");
if (point != null) {
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
......@@ -355,8 +348,7 @@ public class Core extends Application implements ICore, BundleActivator {
// Register the builder with the ItemManager so long as it is not null
if (itemBuilder != null) {
logger.info("ICore Message: Item " + itemBuilder.getItemName()
+ " registered with Core.");
logger.info("ICore Message: Item " + itemBuilder.getItemName() + " registered with Core.");
itemManager.registerBuilder(itemBuilder);
}
......@@ -373,8 +365,7 @@ public class Core extends Application implements ICore, BundleActivator {
// 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);
}
......@@ -398,8 +389,7 @@ public class Core extends Application implements ICore, BundleActivator {
@Override
public String createItem(String itemType) {
// This operation retrieves the default "itemDB
IProject project = ResourcesPlugin.getWorkspace().getRoot()
.getProject("itemDB");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("itemDB");
return createItem(itemType, project);
}
......@@ -421,8 +411,7 @@ public class Core extends Application implements ICore, BundleActivator {
if (itemType != null && project != null) {
newItemId = itemManager.createItem(itemType, project);
} else {
logger.error("Unable to create Item in the core! Type = " + itemType
+ " , project = " + project);
logger.error("Unable to create Item in the core! Type = " + itemType + " , project = " + project);
}
return String.valueOf(newItemId);
......@@ -510,8 +499,7 @@ public class Core extends Application implements ICore, BundleActivator {
* @see ICore#processItem(int itemId, String actionName, int uniqueClientId)
*/
@Override
public FormStatus processItem(int itemId, String actionName,
int uniqueClientId) {
public FormStatus processItem(int itemId, String actionName, int uniqueClientId) {
// Local Declarations
FormStatus status = FormStatus.InfoError;
......@@ -567,77 +555,6 @@ public class Core extends Application implements ICore, BundleActivator {
return itemManager.loadItem(itemFile);
}
/**
* (non-Javadoc)
*
* @see ICore#importFile(URI file)
*/
@Override