Meta m = mapper.readValue(meta, Meta.class);
if (type == null) {
throw new ImporterException(i18n.tr("Wrong metadata type"));
}
ExporterMetadata lastrun = null;
if (ExporterMetadata.TYPE_SYSTEM.equals(type)) {
lastrun = expMetaCurator.lookupByType(type);
}
else if (ExporterMetadata.TYPE_PER_USER.equals(type)) {
if (owner == null) {
throw new ImporterException(i18n.tr("Invalid owner"));
}
lastrun = expMetaCurator.lookupByTypeAndOwner(type, owner);
}
if (lastrun == null) {
// this is our first import, let's create a new entry
lastrun = new ExporterMetadata(type, m.getCreated(), owner);
lastrun = expMetaCurator.create(lastrun);
}
else {
if (lastrun.getExported().after(m.getCreated())) {
if (!forcedConflicts.isForced(Importer.Conflict.MANIFEST_OLD)) {
throw new ImportConflictException(i18n.tr(
"Import is older than existing data"),
Importer.Conflict.MANIFEST_OLD);
}
else {
log.warn("Manifest older than existing data.");
}
}
else {
/*
* Prior to 5.6.4, MySQL did not store fractions of a second in
* temporal values. Consequently, the manifest metadata can end up
* with a created date that is a fraction of a second ahead of
* the created date in the cp_export_metadata table. So we throw away
* the fractions of a second.
*/
long exported = lastrun.getExported().getTime() / 1000;
long created = m.getCreated().getTime() / 1000;
if (exported == created) {
if (!forcedConflicts.isForced(Importer.Conflict.MANIFEST_SAME)) {
throw new ImportConflictException(i18n.tr(
"Import is the same as existing data"),
Importer.Conflict.MANIFEST_SAME);
}
else {
log.warn("Manifest same as existing data.");
}
}
}
lastrun.setExported(m.getCreated());
expMetaCurator.merge(lastrun);
}
}