CCM NG: UserImportTest runs successfully
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5747 8810af33-2d31-482b-a856-94f89814c4df
parent
3fd3b4228e
commit
4eb81c8243
|
|
@ -72,7 +72,9 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||||
public T importEntity(final String data) throws ImportExpection {
|
public T importEntity(final String data) throws ImportExpection {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(data, getEntityClass());
|
final T entity = objectMapper.readValue(data, getEntityClass());
|
||||||
|
saveImportedEntity(entity);
|
||||||
|
return entity;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new ImportExpection(ex);
|
throw new ImportExpection(ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ final class EntityImExporterTreeManager {
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
node -> node
|
node -> node
|
||||||
.getEntityImExporter()
|
.getEntityImExporter()
|
||||||
.getClass()
|
.getEntityClass()
|
||||||
.getAnnotation(Processes.class).value().getName(),
|
.getName(),
|
||||||
node -> node));
|
node -> node));
|
||||||
|
|
||||||
//Add the dependency relations to the nodes
|
//Add the dependency relations to the nodes
|
||||||
|
|
@ -140,7 +140,8 @@ final class EntityImExporterTreeManager {
|
||||||
//Remove the first node from the resolved nodes list
|
//Remove the first node from the resolved nodes list
|
||||||
final EntityImExporterTreeNode current = resolvedNodes.remove(0);
|
final EntityImExporterTreeNode current = resolvedNodes.remove(0);
|
||||||
LOGGER.info("\tProcessing node for EntityImExporter \"{}\"...",
|
LOGGER.info("\tProcessing node for EntityImExporter \"{}\"...",
|
||||||
current.getEntityImExporter().getClass().getName());
|
current
|
||||||
|
.getEntityImExporter().getClass().getName());
|
||||||
|
|
||||||
//Add the node to the ordered modules list.
|
//Add the node to the ordered modules list.
|
||||||
orderedNodes.add(current);
|
orderedNodes.add(current);
|
||||||
|
|
@ -197,7 +198,7 @@ final class EntityImExporterTreeManager {
|
||||||
throws DependencyException {
|
throws DependencyException {
|
||||||
|
|
||||||
//Get the name of the module from the module info.
|
//Get the name of the module from the module info.
|
||||||
final String className = imExporter.getClass().getName();
|
final String className = imExporter.getEntityClass().getName();
|
||||||
LOGGER
|
LOGGER
|
||||||
.info("Adding dependency relations for EntityImExporter \"{}\"...",
|
.info("Adding dependency relations for EntityImExporter \"{}\"...",
|
||||||
className);
|
className);
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ import javax.json.JsonArrayBuilder;
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
import javax.json.JsonObjectBuilder;
|
import javax.json.JsonObjectBuilder;
|
||||||
import javax.json.JsonReader;
|
import javax.json.JsonReader;
|
||||||
|
import javax.json.JsonString;
|
||||||
import javax.json.JsonWriter;
|
import javax.json.JsonWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -137,8 +138,8 @@ public class ImportExport {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileAlreadyExistsException
|
| FileAlreadyExistsException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,7 +196,7 @@ public class ImportExport {
|
||||||
filename));
|
filename));
|
||||||
filesArrayBuilder.add(filename);
|
filesArrayBuilder.add(filename);
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,8 +247,8 @@ public class ImportExport {
|
||||||
importName));
|
importName));
|
||||||
}
|
}
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -276,9 +277,6 @@ public class ImportExport {
|
||||||
.map(EntityImExporterTreeNode::getEntityImExporter)
|
.map(EntityImExporterTreeNode::getEntityImExporter)
|
||||||
.forEach(imExporter -> importEntitiesOfType(importName,
|
.forEach(imExporter -> importEntitiesOfType(importName,
|
||||||
imExporter));
|
imExporter));
|
||||||
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
|
|
||||||
} catch (DependencyException ex) {
|
} catch (DependencyException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -289,9 +287,7 @@ public class ImportExport {
|
||||||
|
|
||||||
final AbstractEntityImExporter<?> imExporter = node
|
final AbstractEntityImExporter<?> imExporter = node
|
||||||
.getEntityImExporter();
|
.getEntityImExporter();
|
||||||
final String type = imExporter
|
final String type = imExporter.getEntityClass().getName();
|
||||||
.getClass()
|
|
||||||
.getAnnotation(Processes.class).value().getName();
|
|
||||||
|
|
||||||
return manifest.getTypes().contains(type);
|
return manifest.getTypes().contains(type);
|
||||||
}
|
}
|
||||||
|
|
@ -300,9 +296,7 @@ public class ImportExport {
|
||||||
final String importName,
|
final String importName,
|
||||||
final AbstractEntityImExporter<?> entityImExporter) {
|
final AbstractEntityImExporter<?> entityImExporter) {
|
||||||
|
|
||||||
final String type = entityImExporter
|
final String type = entityImExporter.getEntityClass().getName();
|
||||||
.getClass()
|
|
||||||
.getAnnotation(Processes.class).value().getName();
|
|
||||||
|
|
||||||
try (final InputStream tocInputStream = ccmFiles
|
try (final InputStream tocInputStream = ccmFiles
|
||||||
.createInputStream(String.format("imports/%s/%s/%s.json",
|
.createInputStream(String.format("imports/%s/%s/%s.json",
|
||||||
|
|
@ -316,13 +310,13 @@ public class ImportExport {
|
||||||
|
|
||||||
files.forEach(value -> importEntity(importName,
|
files.forEach(value -> importEntity(importName,
|
||||||
type,
|
type,
|
||||||
value.toString(),
|
((JsonString) value).getString(),
|
||||||
entityImExporter));
|
entityImExporter));
|
||||||
|
|
||||||
} catch (IOException
|
} catch (IOException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -350,10 +344,10 @@ public class ImportExport {
|
||||||
imExporter.importEntity(data);
|
imExporter.importEntity(data);
|
||||||
|
|
||||||
} catch (IOException
|
} catch (IOException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
| InsufficientPermissionsException
|
| InsufficientPermissionsException
|
||||||
| ImportExpection ex) {
|
| ImportExpection ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,8 +359,8 @@ public class ImportExport {
|
||||||
try {
|
try {
|
||||||
importArchivePaths = ccmFiles.listFiles("imports");
|
importArchivePaths = ccmFiles.listFiles("imports");
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -429,19 +423,24 @@ public class ImportExport {
|
||||||
final LocalDateTime created = LocalDateTime
|
final LocalDateTime created = LocalDateTime
|
||||||
.parse(manifestJson.getString("created"));
|
.parse(manifestJson.getString("created"));
|
||||||
final String onServer = manifestJson.getString("onServer");
|
final String onServer = manifestJson.getString("onServer");
|
||||||
final List<String> types = manifestJson.getJsonArray("types")
|
// final List<String> types = manifestJson.getJsonArray("types")
|
||||||
.stream()
|
// .stream()
|
||||||
.map(value -> value.toString())
|
// .map(value -> value.toString())
|
||||||
.collect(Collectors.toList());
|
// .collect(Collectors.toList());
|
||||||
|
final JsonArray typesArray = manifestJson.getJsonArray("types");
|
||||||
|
final List<String> types = new ArrayList<>();
|
||||||
|
for(int i = 0; i < typesArray.size(); i++) {
|
||||||
|
types.add(typesArray.getString(i));
|
||||||
|
}
|
||||||
|
|
||||||
return new ImportManifest(
|
return new ImportManifest(
|
||||||
Date.from(created.atZone(ZoneId.of("UTC")).toInstant()),
|
Date.from(created.atZone(ZoneId.of("UTC")).toInstant()),
|
||||||
onServer,
|
onServer,
|
||||||
types);
|
types);
|
||||||
} catch (IOException
|
} catch (IOException
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final User entity) {
|
protected void saveImportedEntity(final User entity) {
|
||||||
|
|
||||||
|
// Reset partyId.
|
||||||
|
entity.setPartyId(0);
|
||||||
userRepository.save(entity);
|
userRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
import org.libreccm.core.UnexpectedErrorException;
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
import org.libreccm.files.CcmFilesConfiguration;
|
import org.libreccm.files.CcmFilesConfiguration;
|
||||||
import org.libreccm.security.UserRepository;
|
import org.libreccm.security.Shiro;
|
||||||
import org.libreccm.tests.categories.IntegrationTest;
|
import org.libreccm.tests.categories.IntegrationTest;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
@ -60,8 +60,6 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
@ -82,6 +80,10 @@ public class UserImportTest {
|
||||||
private static final String IMPORT_MANIFEST_SOURCE = "/imports"
|
private static final String IMPORT_MANIFEST_SOURCE = "/imports"
|
||||||
+ "/org.libreccm.imexport.UserImportTest"
|
+ "/org.libreccm.imexport.UserImportTest"
|
||||||
+ "/ccm-export.json";
|
+ "/ccm-export.json";
|
||||||
|
private static final String IMPORT_USERS_TOC_SOURCE = "/imports"
|
||||||
|
+ "/org.libreccm.imexport.UserImportTest"
|
||||||
|
+ "/org.libreccm.security.User"
|
||||||
|
+ "/org.libreccm.security.User.json";
|
||||||
private static final String IMPORT_DATA_SOURCE = "/imports"
|
private static final String IMPORT_DATA_SOURCE = "/imports"
|
||||||
+ "/org.libreccm.imexport.UserImportTest"
|
+ "/org.libreccm.imexport.UserImportTest"
|
||||||
+ "/org.libreccm.security.User"
|
+ "/org.libreccm.security.User"
|
||||||
|
|
@ -100,12 +102,9 @@ public class UserImportTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ImportExport importExport;
|
private ImportExport importExport;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private UserRepository userRepository;
|
private Shiro shiro;
|
||||||
|
|
||||||
@PersistenceContext
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
public UserImportTest() {
|
public UserImportTest() {
|
||||||
|
|
||||||
|
|
@ -143,15 +142,20 @@ public class UserImportTest {
|
||||||
|
|
||||||
final InputStream manifestInputStream = getClass()
|
final InputStream manifestInputStream = getClass()
|
||||||
.getResourceAsStream(IMPORT_MANIFEST_SOURCE);
|
.getResourceAsStream(IMPORT_MANIFEST_SOURCE);
|
||||||
|
final InputStream usersTocInputStream = getClass()
|
||||||
|
.getResourceAsStream(IMPORT_USERS_TOC_SOURCE);
|
||||||
final InputStream user1DataInputStream = getClass()
|
final InputStream user1DataInputStream = getClass()
|
||||||
.getResourceAsStream(IMPORT_DATA_SOURCE);
|
.getResourceAsStream(IMPORT_DATA_SOURCE);
|
||||||
|
|
||||||
final Path manifestTargetPath = userImportsTestDirPath
|
final Path manifestTargetPath = userImportsTestDirPath
|
||||||
.resolve("ccm-export.json");
|
.resolve("ccm-export.json");
|
||||||
|
final Path usersTocTargetPath = importDataPath
|
||||||
|
.resolve("org.libreccm.security.User.json");
|
||||||
final Path user1DataTargetPath = importDataPath
|
final Path user1DataTargetPath = importDataPath
|
||||||
.resolve("7cb9aba4-8071-4f27-af19-096e1473d050.json");
|
.resolve("7cb9aba4-8071-4f27-af19-096e1473d050.json");
|
||||||
|
|
||||||
copy(manifestInputStream, manifestTargetPath);
|
copy(manifestInputStream, manifestTargetPath);
|
||||||
|
copy(usersTocInputStream, usersTocTargetPath);
|
||||||
copy(user1DataInputStream, user1DataTargetPath);
|
copy(user1DataInputStream, user1DataTargetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,7 +287,9 @@ public class UserImportTest {
|
||||||
@InSequence(200)
|
@InSequence(200)
|
||||||
public void importSingleUser() {
|
public void importSingleUser() {
|
||||||
|
|
||||||
importExport.importEntities("org.libreccm.imexport.UserImportTest");
|
shiro.getSystemUser().execute(() ->
|
||||||
|
importExport.importEntities("org.libreccm.imexport.UserImportTest")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"id": 4345,
|
"partyId": 4345,
|
||||||
"uuid": "7cb9aba4-8071-4f27-af19-096e1473d050",
|
"uuid": "7cb9aba4-8071-4f27-af19-096e1473d050",
|
||||||
"name": "janedoe",
|
"name": "janedoe",
|
||||||
"givenName": "Jane",
|
"givenName": "Jane",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"7cb9aba4-8071-4f27-af19-096e1473d050.json"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue