CcmNG: First part of a revised system for import and export.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5696 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
3fce92753e
commit
a926101a29
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
* Interface for exporters. Implementation must be annotated with
|
||||
* {@link Exports} to register the implementation in the Import/Export system.
|
||||
*
|
||||
* Implementations must be CDI beans with annotated with {@link RequestScoped}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T> The type of the entity which is processed by the implementation.
|
||||
*/
|
||||
public interface EntityExporter<T extends Exportable> {
|
||||
|
||||
/**
|
||||
* Converts the provided entity to a JSON object and an optional array of
|
||||
* associations.
|
||||
*
|
||||
* @param entity The entity to export.
|
||||
*
|
||||
* @return The JSON representation of the entity.
|
||||
*/
|
||||
ExportedEntity exportEntity(T entity);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* Imports an entity. Implementations must be annotated with {@link Imports} to
|
||||
* register the implementation in the Import/Export system.
|
||||
*
|
||||
* Implementations must be CDI beans with annotated with {@link RequestScoped}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T> The entity type which can processed by the implementation.
|
||||
*/
|
||||
public interface EntityImporter<T extends Exportable> {
|
||||
|
||||
T importEntity(JsonObject data);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
/**
|
||||
* Every entity which is suitable for importing and exporting must implement
|
||||
* this interface.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public interface Exportable {
|
||||
|
||||
/**
|
||||
* Return the UUID of the entity which identifies the object independently
|
||||
* from any database primary keys.
|
||||
*
|
||||
* @return The UUID of implementing entity.
|
||||
*/
|
||||
String getUuid();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
|
||||
/**
|
||||
* A transfer object used by {@link Exporter} to wrap the exported object and
|
||||
* optionally the associations extracted from the object.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ExportedEntity {
|
||||
|
||||
private final JsonObject entity;
|
||||
private final JsonArray associations;
|
||||
|
||||
public ExportedEntity(final JsonObject entity) {
|
||||
|
||||
this.entity = Objects.requireNonNull(entity);
|
||||
this.associations = null;
|
||||
}
|
||||
|
||||
public ExportedEntity(final JsonObject entity,
|
||||
final JsonArray associations) {
|
||||
|
||||
this.entity = Objects.requireNonNull(entity);
|
||||
this.associations = Objects.requireNonNull(associations);
|
||||
}
|
||||
|
||||
public JsonObject getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Optional<JsonArray> getAssociations() {
|
||||
return Optional.of(associations);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Declares which entity type a implementation of {@link Exporter} can process.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
@Target({ElementType.TYPE,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD})
|
||||
public @interface Exports {
|
||||
|
||||
Class<? extends Exportable> value();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
|
||||
import org.libreccm.files.CcmFilesConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Central service for importing and exporting entities.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
public class ImportExport {
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
private Instance<EntityImporter<?>> importers;
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
private Instance<EntityExporter<?>> exporters;
|
||||
|
||||
/**
|
||||
* Exports the provided entities. The export will be written to a to the
|
||||
* {@code exports} directory in the CCM files directory. If {@code split} is
|
||||
* {@code false} a file with the name provided by {@link exportName} will be
|
||||
* generated. Otherwise a directory with the provided name will be
|
||||
* generated. All files will be placed into that directory. For the main
|
||||
* file the provided name will be used.
|
||||
*
|
||||
*
|
||||
* @param entities The entities to export.
|
||||
* @param exportName The name file to which the export is written.
|
||||
* @param split Split the entities by package?
|
||||
*
|
||||
* @see CcmFilesConfiguration#dataPath
|
||||
*/
|
||||
public void exportEntities(final List<Exportable> entities,
|
||||
final String exportName,
|
||||
final boolean split) {
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports all entities from the files in the {@link imports} directory inside
|
||||
* the CCM files data directory. The data to import can either be a file with
|
||||
* the provided name or a directory with the provided name. If it is a directory
|
||||
* the entry file must also use the provided name.
|
||||
*
|
||||
* If an entity which is part of the import already exists in the database
|
||||
* the values from the import are used to update the entity.
|
||||
*
|
||||
* @param importName The name of the import.
|
||||
*
|
||||
* @see CcmFilesConfiguration#dataPath
|
||||
*/
|
||||
public void importEntities(final String importName) {
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.imexport;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Declares which entity types an implementation of {@link Importer} can
|
||||
* process.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
@Target({ElementType.TYPE,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD})
|
||||
public @interface Imports {
|
||||
|
||||
Class<? extends Exportable> value();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue