Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import template #4367

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cafa316
Add a template to import config.
ximenesuk Mar 5, 2015
5b65e7a
Allow template to be passed in via importer-cli, but don't document.
ximenesuk Mar 5, 2015
2182586
Changes to ImportLibrary
ximenesuk Mar 5, 2015
85d2c28
Changes to OMEROMetadataStoreClient
ximenesuk Mar 5, 2015
b2fc6dd
Add ImportTemplate class.
ximenesuk Mar 10, 2015
3f99c8e
Create o.f.i.targets package
joshmoore May 18, 2015
f53499b
Initial migration to ImportTarget interface
joshmoore May 18, 2015
ae0ff55
Re-collapse path targets to TemplateImportTarget
joshmoore May 19, 2015
8c54272
template: More moving methods
joshmoore Jun 1, 2015
e91512b
model: implement and throw
joshmoore Jun 1, 2015
8c3f240
cli: rename template argument
joshmoore Jun 1, 2015
f22dddc
cli: use target rather than -d and -r
joshmoore Jun 1, 2015
41bbe1a
targets: improve exceptions
joshmoore Jun 1, 2015
db07411
fix: re-collapse
joshmoore Jun 1, 2015
64fcb09
import.py: add -T arguments
joshmoore Jun 1, 2015
8708075
tests: work on unit and integration tests
joshmoore Jun 1, 2015
2cbed18
Initial working `-T` flag
joshmoore Jul 15, 2015
070cf10
Server-side template attempt
joshmoore Jul 22, 2015
8fc1bee
Use client path for TemplateImportTarget
joshmoore Jul 30, 2015
aff08b5
Working model & template sources
joshmoore Jul 30, 2015
52e85d0
This is no longer failing as expected
joshmoore Jul 30, 2015
885f23d
Working $Class:name:$Name target
joshmoore Jul 30, 2015
0849583
Fix flake8
joshmoore Jul 30, 2015
6a4f53c
Allow deprecated -d and -r to work with new target
Dec 2, 2015
0b0fce6
ClientPathExclusion: add new --exclude option
joshmoore Sep 29, 2015
8765c3f
Fix JavaDoc error and remove blank line
Dec 3, 2015
eaef41d
Use more explicit Container1 instead of C1
Dec 7, 2015
bd78312
Restrict target classes to Dataset and Screen
Dec 8, 2015
887a45a
Handle multiple containers with the same name
Dec 9, 2015
4210389
Extend helper method to take object name
Dec 9, 2015
8435f54
Add method to get single screen as fake can have screens=0
Dec 9, 2015
01fc45d
Add test for multiple named targets
Dec 9, 2015
1b677de
Switch to find by query
Dec 9, 2015
60e0354
Use newest container, ie highest id
Dec 9, 2015
d9834e5
Use screens=0 in fakes to simply tests
Dec 9, 2015
bb9a798
Now factor out parse_containers
Dec 9, 2015
25012e6
Move flag to source class
Dec 9, 2015
777d749
Add both legacy uses to source classes and remove old tests
Dec 9, 2015
ce2c0a9
Refactor source classes
Dec 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions components/blitz/resources/omero/Constants.ice
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module omero {
const string NSFSRENAME = "openmicroscopy.org/omero/fs/rename";
const string NSMEASUREMENT = "openmicroscopy.org/omero/measurement";
const string NSAUTOCLOSE = "openmicroscopy.org/omero/import/autoClose";
const string NSTARGETTEMPLATE = "openmicroscopy.org/omero/import/targetTemplate";
const string NSCOMPANIONFILE = "openmicroscopy.org/omero/import/companionFile";
const string NSLOGFILE = "openmicroscopy.org/omero/import/logFile";
const string NSFILETRANSFER = "openmicroscopy.org/omero/import/fileTransfer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,8 @@ public <T extends IObject> T getTarget(Class<T> klass, long id)
}

/**
* @param projectId the ID of the project
* @return the project
* @param projectId
* @return project with given id
*/
public Project getProject(long projectId)
{
Expand Down
39 changes: 39 additions & 0 deletions components/blitz/src/ome/formats/importer/ImportConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import loci.formats.FormatTools;
import ome.formats.OMEROMetadataStoreClient;
import ome.formats.importer.targets.ImportTarget;
import ome.formats.importer.targets.TargetBuilder;
import ome.formats.importer.util.IniFileLoader;
import ome.system.PreferenceContext;
import ome.system.UpgradeCheck;
Expand All @@ -49,6 +51,12 @@ public class ImportConfig {

private final static Logger log = LoggerFactory.getLogger(ImportConfig.class);

/** The class used to identify the dataset target.*/
private static final String DATASET_CLASS = "omero.model.Dataset";

/** The class used to identify the screen target.*/
private static final String SCREEN_CLASS = "omero.model.Screen";

/**
* Delimiter used to encode multiple servers in one preferences value.
*/
Expand Down Expand Up @@ -111,9 +119,15 @@ public class ImportConfig {
public final StrValue email;
public final StrValue userSpecifiedName;
public final StrValue userSpecifiedDescription;

@Deprecated
public final StrValue targetClass;

@Deprecated
public final LongValue targetId;

public final StrValue target;

public final BoolValue debug;
public final BoolValue contOnError;
public final BoolValue sendReport;
Expand Down Expand Up @@ -253,6 +267,7 @@ public synchronized void load() {
userSpecifiedDescription = new StrValue("userSpecifiedDescription", this);
targetClass = new StrValue("targetClass", this);
targetId = new LongValue("targetId", this, 0L);
target = new StrValue("target", this);

savedProject = new LongValue("savedProject", this, 0L);
savedDataset = new LongValue("savedDataset", this, 0L);
Expand Down Expand Up @@ -1019,4 +1034,28 @@ public File get() {
}
}
}

public ImportTarget getTarget() {
TargetBuilder builder = new TargetBuilder();
if (target.get() != null)
{
ImportTarget t = builder.parse(target.get()).build();
log.info("Using import target: {}", target);
return t;
}
if (DATASET_CLASS.equals(targetClass.get()))
{
return builder.parse(
String.format("%s:%s", DATASET_CLASS, targetId.get()))
.build();
}
else if (SCREEN_CLASS.equals(targetClass.get()))
{
return builder.parse(
String.format("%s:%s", SCREEN_CLASS, targetId.get()))
.build();
}
return null;
}

}
35 changes: 19 additions & 16 deletions components/blitz/src/ome/formats/importer/ImportLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import loci.formats.FormatException;
import loci.formats.FormatReader;
import ome.formats.OMEROMetadataStoreClient;
import ome.formats.importer.ImportEvent.FILESET_EXCLUSION;
import ome.formats.importer.exclusions.FileExclusion;
import ome.formats.importer.targets.ImportTarget;
import ome.formats.importer.transfers.FileTransfer;
import ome.formats.importer.transfers.TransferState;
import ome.formats.importer.transfers.UploadFileTransfer;
Expand Down Expand Up @@ -67,6 +67,7 @@
import omero.grid.ManagedRepositoryPrxHelper;
import omero.grid.RepositoryMap;
import omero.grid.RepositoryPrx;
import omero.model.Annotation;
import omero.model.ChecksumAlgorithm;
import omero.model.Dataset;
import omero.model.Fileset;
Expand Down Expand Up @@ -102,12 +103,6 @@ public class ImportLibrary implements IObservable
{
private static Logger log = LoggerFactory.getLogger(ImportLibrary.class);

/** The class used to identify the dataset target.*/
private static final String DATASET_CLASS = "omero.model.Dataset";

/** The class used to identify the screen target.*/
private static final String SCREEN_CLASS = "omero.model.Screen";

/* checksum provider factory for verifying file integrity in upload */
private static final ChecksumProviderFactory checksumProviderFactory = new ChecksumProviderFactoryImpl();

Expand Down Expand Up @@ -269,15 +264,22 @@ public boolean importCandidates(ImportConfig config, ImportCandidates candidates
int numDone = 0;
for (int index = 0; index < containers.size(); index++) {
ImportContainer ic = containers.get(index);
if (DATASET_CLASS.equals(config.targetClass.get()))
{
ic.setTarget(store.getTarget(
Dataset.class, config.targetId.get()));
}
else if (SCREEN_CLASS.equals(config.targetClass.get()))
{
ic.setTarget(store.getTarget(
Screen.class, config.targetId.get()));
ImportTarget target = config.getTarget();
if (target != null) {
try {
IObject obj = target.load(store, ic);
if (!(obj instanceof Annotation)) {
ic.setTarget(obj);
} else {
// This is likely a "post-processing" annotation
// so that we don't have to resolve the target
// until later.
ic.getCustomAnnotationList().add((Annotation) obj);
}
} catch (Exception e) {
log.error("Could not load target: {}", target);
throw new RuntimeException("Failed to load target", e);
}
}

if (config.checksumAlgorithm.get() != null) {
Expand Down Expand Up @@ -348,6 +350,7 @@ public ImportProcessPrx createImport(final ImportContainer container)
notifyObservers(new ImportEvent.FILESET_UPLOAD_PREPARATION(
null, 0, usedFiles.length, null, null, null));

// Copied to ClientPathExclusion
// TODO: allow looser sanitization according to server configuration
final FilePathRestrictions portableRequiredRules =
FilePathRestrictionInstance.getFilePathRestrictions(FilePathRestrictionInstance.WINDOWS_REQUIRED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import loci.formats.in.DefaultMetadataOptions;
import loci.formats.in.MetadataLevel;
Expand All @@ -42,8 +42,6 @@
import omero.grid.ImportProcessPrxHelper;
import omero.model.Annotation;
import omero.model.CommentAnnotationI;
import omero.model.Dataset;
import omero.model.Screen;

import org.apache.commons.lang.time.StopWatch;
import org.slf4j.Logger;
Expand Down Expand Up @@ -351,6 +349,7 @@ public static void usage() {
+ " -l READER_FILE\t\t\tUse the list of readers rather than the default\n"
+ " -d DATASET_ID\t\t\t\tOMERO dataset ID to import image into\n"
+ " -r SCREEN_ID\t\t\t\tOMERO screen ID to import plate into\n"
+ " -T TARGET\t\t\t\ttarget for imports\n"

+ " --report\t\t\t\tReport errors to the OME team\n"
+ " --upload\t\t\t\tUpload broken files and log file (if any) with report. Required --report\n"
Expand Down Expand Up @@ -418,6 +417,7 @@ public static void advUsage() {
+ " File exclusion:\n"
+ " ---------------\n\n"
+ " --exclude=filename \tExclude files based on filename.\n\n"
+ " --exclude=clientpath \tExclude files based on the original path.\n\n"
+ "\n"
+ " e.g. $ bin/omero import -- --exclude=filename foo.tiff # First-time imports\n"
+ " $ bin/omero import -- --exclude=filename foo.tiff # Second-time skips\n"
Expand Down Expand Up @@ -557,13 +557,16 @@ public static void main(String[] args) throws Exception {
LongOpt exclude =
new LongOpt("exclude", LongOpt.REQUIRED_ARGUMENT, null, 20);

LongOpt target =
new LongOpt("target", LongOpt.REQUIRED_ARGUMENT, null, 21);

LongOpt qaBaseURL = new LongOpt(
"qa-baseurl", LongOpt.REQUIRED_ARGUMENT, null, 21);
"qa-baseurl", LongOpt.REQUIRED_ARGUMENT, null, 22);

LongOpt noStatsInfo =
new LongOpt("no-stats-info", LongOpt.NO_ARGUMENT, null, 22);
new LongOpt("no-stats-info", LongOpt.NO_ARGUMENT, null, 23);
LongOpt noUpgradeCheck =
new LongOpt("no-upgrade-check", LongOpt.NO_ARGUMENT, null, 23);
new LongOpt("no-upgrade-check", LongOpt.NO_ARGUMENT, null, 24);

// DEPRECATED OPTIONS
LongOpt plateName = new LongOpt(
Expand All @@ -581,14 +584,14 @@ public static void main(String[] args) throws Exception {
LongOpt annotationLinkDeprecated =
new LongOpt("annotation_link", LongOpt.REQUIRED_ARGUMENT, null, 96);

Getopt g = new Getopt(APP_NAME, args, "cfl:s:u:w:d:r:k:x:n:p:h",
Getopt g = new Getopt(APP_NAME, args, "cfl:s:u:w:d:r:T:k:x:n:p:h",
new LongOpt[] { debug, report, upload, logs, email,
name, description, noThumbnails,
agent, annotationNamespace, annotationText,
annotationLink, transferOpt, advancedHelp,
checksumAlgorithm, minutesWait,
closeCompleted, waitCompleted, autoClose,
exclude, noStatsInfo,
exclude, target, noStatsInfo,
noUpgradeCheck, qaBaseURL,
plateName, plateDescription,
noThumbnailsDeprecated,
Expand Down Expand Up @@ -713,16 +716,21 @@ public static void main(String[] args) throws Exception {
}
break;
}
case 'T':
case 21: {
config.qaBaseURL.set(g.getOptarg());
config.target.set(g.getOptarg());
break;
}
case 22: {
config.qaBaseURL.set(g.getOptarg());
break;
}
case 23: {
log.info("Skipping minimum/maximum computation");
config.noStatsInfo.set(true);
break;
}
case 23: {
case 24: {
log.info("Disabling upgrade check");
config.checkUpgrade.set(false);
break;
Expand Down Expand Up @@ -786,22 +794,18 @@ public static void main(String[] args) throws Exception {
}
case 'd': {
String datasetString = g.getOptarg();
if (datasetString.startsWith("Dataset:")) {
datasetString = datasetString.substring(
"Dataset:".length());
if (!datasetString.startsWith("Dataset:")) {
datasetString = "Dataset:" + Long.valueOf(datasetString).toString();
}
config.targetId.set(Long.parseLong(datasetString));
config.targetClass.set(Dataset.class.getName());
config.target.set(datasetString);
break;
}
case 'r': {
String screenString = g.getOptarg();
if (screenString.startsWith("Screen:")) {
screenString = screenString.substring(
"Screen:".length());
if (!screenString.startsWith("Screen:")) {
screenString = "Screen:" + Long.valueOf(screenString).toString();
}
config.targetId.set(Long.parseLong(screenString));
config.targetClass.set(Screen.class.getName());
config.target.set(screenString);
break;
}
case 'n': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public abstract class AbstractFileExclusion implements FileExclusion {
* Enum of well-known {@link FileExclusion} names.
*/
public enum Exclusion {
filename(FilenameExclusion.class);
filename(FilenameExclusion.class),
clientpath(ClientPathExclusion.class);
Class<?> kls;
Exclusion(Class<?> kls) {
this.kls = kls;
Expand Down Expand Up @@ -82,4 +83,4 @@ protected String checksum(String filename, ChecksumAlgorithm checksumAlgorithm)
return cp.checksumAsString();
}

}
}