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