Code reformatting and cleanup
parent
c65c182e14
commit
c77dc2f991
|
|
@ -26,42 +26,51 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used by the {@link CategorizationImExporter} to resolve categories based on
|
||||||
|
* their UUIDs.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class CategoryIdResolver implements Serializable, ObjectIdResolver {
|
public class CategoryIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -5750627754502675522L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey,
|
public void bindItem(
|
||||||
Object pojo) {
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final CategoryRepository categoryRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(CategoryRepository.class);
|
.findBean(CategoryRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return categoryRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No Category with uuid %s in the database.",
|
"No Category with uuid %s in the database.",
|
||||||
id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object context) {
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
return new CategoryIdResolver();
|
return new CategoryIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof CategoryIdResolver;
|
return resolverType instanceof CategoryIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,41 +26,50 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
* Used to resolve {@link Domain}s for import/export based on their UUIDs.
|
||||||
* @version created the 8/2/17
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class DomainIdResolver implements Serializable, ObjectIdResolver {
|
public class DomainIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -8504371142795445708L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey, Object o) {
|
public void bindItem(
|
||||||
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final DomainRepository domainRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(DomainRepository.class);
|
.findBean(DomainRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return domainRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No Domain with uuid %s in the database.",
|
"No Domain with uuid %s in the database.",
|
||||||
id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object o) {
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
return new DomainIdResolver();
|
return new DomainIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof DomainIdResolver;
|
return resolverType instanceof DomainIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,32 +26,41 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
* Used to resolve {@link CcmObject}s based on their UUIDs when importing and
|
||||||
* @version created on 3/23/17
|
* exporting them.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = 246452778202614974L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey,
|
public void bindItem(
|
||||||
Object pojo) {
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final CcmObjectRepository ccmObjectRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(CcmObjectRepository.class);
|
.findBean(CcmObjectRepository.class)
|
||||||
|
.findObjectByUuid(id.key.toString())
|
||||||
return ccmObjectRepository
|
.orElseThrow(
|
||||||
.findObjectByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No CcmObject with uuid %s in the database.",
|
"No CcmObject with uuid %s in the database.",
|
||||||
id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -63,4 +72,5 @@ public class CcmObjectIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof CcmObjectIdResolver;
|
return resolverType instanceof CcmObjectIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,40 +26,52 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
* Used to resolve {@link Resource}s based on their UUID when import or
|
||||||
* @version created the 8/10/17
|
* exporting them.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class ResourceIdResolver implements Serializable, ObjectIdResolver {
|
public class ResourceIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -402304483886269532L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey, Object o) {
|
public void bindItem(
|
||||||
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final ResourceRepository resourceRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(ResourceRepository.class);
|
.findBean(ResourceRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return resourceRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No Resource with uuid %s in the database.",
|
"No Resource with uuid %s in the database.",
|
||||||
id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object o) {
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
return new ResourceIdResolver();
|
return new ResourceIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof ResourceIdResolver;
|
return resolverType instanceof ResourceIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,41 +26,51 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
* Used to resolve {@link ResourceType}s based in their UUID when importing or
|
||||||
* @version created the 8/10/17
|
* exporting them.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class ResourceTypeIdResolver implements Serializable, ObjectIdResolver {
|
public class ResourceTypeIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -3756063950193704821L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey, Object o) {
|
public void bindItem(
|
||||||
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final ResourceTypeRepository resourceTypeRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(ResourceTypeRepository.class);
|
.findBean(ResourceTypeRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return resourceTypeRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No ResourceType with uuid %s in the " +
|
"No ResourceType with uuid %s in the database.",
|
||||||
"database.",
|
id.key.toString()
|
||||||
id.key.toString())));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object o) {
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
return new ResourceTypeIdResolver();
|
return new ResourceTypeIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof ResourceTypeIdResolver;
|
return resolverType instanceof ResourceTypeIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,14 +110,19 @@ public class ImportExport {
|
||||||
*/
|
*/
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public void exportEntities(
|
public void exportEntities(
|
||||||
final Collection<Exportable> entities, final String exportName
|
final Collection<Exportable> entities,
|
||||||
|
final String exportName
|
||||||
) {
|
) {
|
||||||
final JsonObjectBuilder manifestBuilder = Json.createObjectBuilder();
|
final JsonObjectBuilder manifestBuilder = Json.createObjectBuilder();
|
||||||
manifestBuilder.add("created",
|
manifestBuilder.add(
|
||||||
LocalDateTime.now(ZoneId.of("UTC")).toString());
|
"created",
|
||||||
|
LocalDateTime.now(ZoneId.of("UTC")).toString()
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
manifestBuilder.add("onServer",
|
manifestBuilder.add(
|
||||||
InetAddress.getLocalHost().getHostName());
|
"onServer",
|
||||||
|
InetAddress.getLocalHost().getHostName()
|
||||||
|
);
|
||||||
} catch (UnknownHostException ex) {
|
} catch (UnknownHostException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -134,9 +139,13 @@ public class ImportExport {
|
||||||
ccmFiles.createDirectory(String.format("exports/%s", exportName));
|
ccmFiles.createDirectory(String.format("exports/%s", exportName));
|
||||||
|
|
||||||
for (final String type : types) {
|
for (final String type : types) {
|
||||||
ccmFiles.createDirectory(String.format("exports/%s/%s",
|
ccmFiles.createDirectory(
|
||||||
exportName,
|
String.format(
|
||||||
type));
|
"exports/%s/%s",
|
||||||
|
exportName,
|
||||||
|
type
|
||||||
|
)
|
||||||
|
);
|
||||||
typesArrayBuilder.add(type);
|
typesArrayBuilder.add(type);
|
||||||
|
|
||||||
final List<Exportable> entitiesOfType = entities
|
final List<Exportable> entitiesOfType = entities
|
||||||
|
|
@ -149,9 +158,13 @@ public class ImportExport {
|
||||||
|
|
||||||
manifestBuilder.add("types", typesArrayBuilder);
|
manifestBuilder.add("types", typesArrayBuilder);
|
||||||
final OutputStream manifestOutputStream = ccmFiles
|
final OutputStream manifestOutputStream = ccmFiles
|
||||||
.createOutputStream(String.format("exports/%s/ccm-export.json",
|
.createOutputStream(
|
||||||
exportName));
|
String.format(
|
||||||
try (JsonWriter manifestWriter = Json.
|
"exports/%s/ccm-export.json",
|
||||||
|
exportName
|
||||||
|
)
|
||||||
|
);
|
||||||
|
try ( JsonWriter manifestWriter = Json.
|
||||||
createWriter(manifestOutputStream)) {
|
createWriter(manifestOutputStream)) {
|
||||||
|
|
||||||
manifestWriter.writeObject(manifestBuilder.build());
|
manifestWriter.writeObject(manifestBuilder.build());
|
||||||
|
|
@ -165,9 +178,11 @@ public class ImportExport {
|
||||||
|
|
||||||
for (final Map.Entry<String, List<Exportable>> entry
|
for (final Map.Entry<String, List<Exportable>> entry
|
||||||
: typeEntityMap.entrySet()) {
|
: typeEntityMap.entrySet()) {
|
||||||
createExportedEntities(exportName,
|
createExportedEntities(
|
||||||
entry.getKey(),
|
exportName,
|
||||||
entry.getValue());
|
entry.getKey(),
|
||||||
|
entry.getValue()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,15 +205,15 @@ public class ImportExport {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!ccmFiles.isDirectory(importsPath)) {
|
if (!ccmFiles.isDirectory(importsPath)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
throw new IllegalArgumentException(String.format(
|
String.format(
|
||||||
"No imports with name \"%s\" available.",
|
"No imports with name \"%s\" available.",
|
||||||
importName));
|
importName)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,16 +239,21 @@ public class ImportExport {
|
||||||
importers
|
importers
|
||||||
.stream()
|
.stream()
|
||||||
.map(EntityImExporterTreeNode::getEntityImExporter)
|
.map(EntityImExporterTreeNode::getEntityImExporter)
|
||||||
.forEach(imExporter -> importEntitiesOfType(importName,
|
.forEach(
|
||||||
imExporter));
|
imExporter -> importEntitiesOfType(
|
||||||
|
importName,
|
||||||
|
imExporter
|
||||||
|
)
|
||||||
|
);
|
||||||
} catch (DependencyException ex) {
|
} catch (DependencyException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean filterImporters(final ImportManifest manifest,
|
private boolean filterImporters(
|
||||||
final EntityImExporterTreeNode node) {
|
final ImportManifest manifest,
|
||||||
|
final EntityImExporterTreeNode node
|
||||||
|
) {
|
||||||
final AbstractEntityImExporter<?> imExporter = node
|
final AbstractEntityImExporter<?> imExporter = node
|
||||||
.getEntityImExporter();
|
.getEntityImExporter();
|
||||||
final String type = imExporter.getEntityClass().getName();
|
final String type = imExporter.getEntityClass().getName();
|
||||||
|
|
@ -243,53 +263,60 @@ public class ImportExport {
|
||||||
|
|
||||||
private void importEntitiesOfType(
|
private void importEntitiesOfType(
|
||||||
final String importName,
|
final String importName,
|
||||||
final AbstractEntityImExporter<?> entityImExporter) {
|
final AbstractEntityImExporter<?> entityImExporter
|
||||||
|
) {
|
||||||
final String type = entityImExporter.getEntityClass().getName();
|
final String type = entityImExporter.getEntityClass().getName();
|
||||||
|
|
||||||
try (final InputStream tocInputStream = ccmFiles
|
final String tocPath = String.format(
|
||||||
.createInputStream(String.format("imports/%s/%s/%s.json",
|
"imports/%s/%s/%s.json",
|
||||||
importName,
|
importName,
|
||||||
type,
|
type,
|
||||||
type))) {
|
type
|
||||||
|
);
|
||||||
|
try (final InputStream tocInputStream = ccmFiles.createInputStream(
|
||||||
|
tocPath
|
||||||
|
)) {
|
||||||
final JsonReader tocReader = Json.createReader(tocInputStream);
|
final JsonReader tocReader = Json.createReader(tocInputStream);
|
||||||
final JsonObject toc = tocReader.readObject();
|
final JsonObject toc = tocReader.readObject();
|
||||||
final JsonArray files = toc.getJsonArray("files");
|
final JsonArray files = toc.getJsonArray("files");
|
||||||
|
|
||||||
files.forEach(value -> importEntity(importName,
|
files.forEach(
|
||||||
type,
|
value -> importEntity(
|
||||||
((JsonString) value).getString(),
|
importName,
|
||||||
entityImExporter));
|
type,
|
||||||
|
((JsonString) value).getString(),
|
||||||
|
entityImExporter
|
||||||
|
)
|
||||||
|
);
|
||||||
} catch (IOException
|
} catch (IOException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importEntity(final String importName,
|
private void importEntity(
|
||||||
final String type,
|
final String importName,
|
||||||
final String fileName,
|
final String type,
|
||||||
final AbstractEntityImExporter<?> imExporter) {
|
final String fileName,
|
||||||
|
final AbstractEntityImExporter<?> imExporter
|
||||||
final String filePath = String.format("imports/%s/%s/%s",
|
) {
|
||||||
importName,
|
final String filePath = String.format(
|
||||||
type,
|
"imports/%s/%s/%s",
|
||||||
fileName);
|
importName,
|
||||||
try (final InputStream inputStream
|
type,
|
||||||
= ccmFiles.createInputStream(filePath)) {
|
fileName
|
||||||
|
);
|
||||||
|
try (final InputStream inputStream = ccmFiles.createInputStream(
|
||||||
|
filePath
|
||||||
|
)) {
|
||||||
final String data = new BufferedReader(
|
final String data = new BufferedReader(
|
||||||
new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
new InputStreamReader(inputStream, StandardCharsets.UTF_8))
|
||||||
.lines()
|
.lines()
|
||||||
.collect(Collectors.joining("\n"));
|
.collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
imExporter.importEntity(data);
|
imExporter.importEntity(data);
|
||||||
|
|
||||||
} catch (IOException
|
} catch (IOException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
|
|
@ -301,14 +328,12 @@ public class ImportExport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ImportManifest> listAvailableImportArchivies() {
|
public List<ImportManifest> listAvailableImportArchivies() {
|
||||||
|
|
||||||
final List<String> importArchivePaths;
|
final List<String> importArchivePaths;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,14 +362,20 @@ public class ImportExport {
|
||||||
|
|
||||||
final AbstractEntityImExporter<?> imExporter;
|
final AbstractEntityImExporter<?> imExporter;
|
||||||
if (instance.isUnsatisfied()) {
|
if (instance.isUnsatisfied()) {
|
||||||
throw new UnexpectedErrorException(String.format(
|
throw new UnexpectedErrorException(
|
||||||
"No EntityImExporter for entity type \"%s\" available.",
|
String.format(
|
||||||
type));
|
"No EntityImExporter for entity type \"%s\" available.",
|
||||||
|
type
|
||||||
|
)
|
||||||
|
);
|
||||||
} else if (instance.isAmbiguous()) {
|
} else if (instance.isAmbiguous()) {
|
||||||
throw new UnexpectedErrorException(String.format(
|
throw new UnexpectedErrorException(
|
||||||
"Instance reference for EntityImExporter for entity "
|
String.format(
|
||||||
+ "type \"%s\" is ambiguous.",
|
"Instance reference for EntityImExporter for entity "
|
||||||
type));
|
+ "type \"%s\" is ambiguous.",
|
||||||
|
type
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
imExporter = instance.get();
|
imExporter = instance.get();
|
||||||
}
|
}
|
||||||
|
|
@ -354,11 +385,14 @@ public class ImportExport {
|
||||||
final String filename = String.format("%s.json", entity.getUuid());
|
final String filename = String.format("%s.json", entity.getUuid());
|
||||||
final OutputStream outputStream;
|
final OutputStream outputStream;
|
||||||
try {
|
try {
|
||||||
outputStream = ccmFiles.createOutputStream(String.format(
|
outputStream = ccmFiles.createOutputStream(
|
||||||
"exports/%s/%s/%s",
|
String.format(
|
||||||
exportName,
|
"exports/%s/%s/%s",
|
||||||
type,
|
exportName,
|
||||||
filename));
|
type,
|
||||||
|
filename
|
||||||
|
)
|
||||||
|
);
|
||||||
filesArrayBuilder.add(filename);
|
filesArrayBuilder.add(filename);
|
||||||
} catch (FileAccessException
|
} catch (FileAccessException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
@ -372,10 +406,10 @@ public class ImportExport {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
try (final OutputStreamWriter writer = new OutputStreamWriter(
|
try (final OutputStreamWriter writer = new OutputStreamWriter(
|
||||||
outputStream, StandardCharsets.UTF_8)) {
|
outputStream,
|
||||||
|
StandardCharsets.UTF_8
|
||||||
|
)) {
|
||||||
writer.write(exportedEntity);
|
writer.write(exportedEntity);
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -385,15 +419,15 @@ public class ImportExport {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isImportArchive(final String path) {
|
private boolean isImportArchive(final String path) {
|
||||||
|
final String manifestPath = String.format(
|
||||||
final String manifestPath = String.format("imports/%s/ccm-export.json",
|
"imports/%s/ccm-export.json",
|
||||||
path);
|
path
|
||||||
|
);
|
||||||
|
|
||||||
final boolean result;
|
final boolean result;
|
||||||
try {
|
try {
|
||||||
result = ccmFiles.existsFile(manifestPath);
|
result = ccmFiles.existsFile(manifestPath);
|
||||||
} catch (FileAccessException | InsufficientPermissionsException ex) {
|
} catch (FileAccessException | InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,7 +435,6 @@ public class ImportExport {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImportManifest createImportManifest(final String path) {
|
private ImportManifest createImportManifest(final String path) {
|
||||||
|
|
||||||
final String manifestPath = String.format(
|
final String manifestPath = String.format(
|
||||||
"imports/%s/ccm-export.json", path
|
"imports/%s/ccm-export.json", path
|
||||||
);
|
);
|
||||||
|
|
@ -465,7 +498,6 @@ public class ImportExport {
|
||||||
| FileAccessException
|
| FileAccessException
|
||||||
| FileDoesNotExistException
|
| FileDoesNotExistException
|
||||||
| InsufficientPermissionsException ex) {
|
| InsufficientPermissionsException ex) {
|
||||||
|
|
||||||
throw new UnexpectedErrorException(ex);
|
throw new UnexpectedErrorException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -484,7 +516,6 @@ public class ImportExport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Exportable> value() {
|
public Class<? extends Exportable> value() {
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,16 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link Group}s when importing or exporting them.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class GroupIdResolver implements Serializable, ObjectIdResolver {
|
public class GroupIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = 3700628942920771114L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -43,16 +48,18 @@ public class GroupIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
|
return CdiUtil
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
.createCdiUtil()
|
||||||
final GroupRepository groupRepo = cdiUtil
|
.findBean(GroupRepository.class)
|
||||||
.findBean(GroupRepository.class);
|
.findByUuid(id.key.toString())
|
||||||
|
.orElseThrow(
|
||||||
return groupRepo
|
() -> new IllegalArgumentException(
|
||||||
.findByUuid(id.key.toString())
|
String.format(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
"No Group with uuid %s in the database.",
|
||||||
.format("No Group with uuid %s in the database.",
|
id.key.toString()
|
||||||
id.key.toString())));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,4 +71,5 @@ public class GroupIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver objectIdResolver) {
|
public boolean canUseFor(final ObjectIdResolver objectIdResolver) {
|
||||||
return objectIdResolver instanceof GroupIdResolver;
|
return objectIdResolver instanceof GroupIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link Party} entities when import or exporting them.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @version created on 3/23/17
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class PartyIdResolver implements Serializable, ObjectIdResolver {
|
public class PartyIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -1208121020457080214L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -44,16 +48,18 @@ public class PartyIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
|
return CdiUtil
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
.createCdiUtil()
|
||||||
final PartyRepository partyRepository = cdiUtil
|
.findBean(PartyRepository.class)
|
||||||
.findBean(PartyRepository.class);
|
.findByUuid(id.key.toString())
|
||||||
|
.orElseThrow(
|
||||||
return partyRepository
|
() -> new IllegalArgumentException(
|
||||||
.findByUuid(id.key.toString())
|
String.format(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
"No Party with uuid %s in the database.",
|
||||||
.format("No Party with uuid %s in the database.",
|
id.key.toString()
|
||||||
id.key.toString())));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -65,4 +71,5 @@ public class PartyIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof PartyIdResolver;
|
return resolverType instanceof PartyIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,22 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link Permission}s based on their UUID when importing or
|
||||||
|
* exporting them.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class PermissionIdResolver implements Serializable, ObjectIdResolver {
|
public class PermissionIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -8397366681202009916L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -45,16 +50,18 @@ public class PermissionIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
|
return CdiUtil
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
.createCdiUtil()
|
||||||
final PermissionRepository permissionRepository = cdiUtil
|
.findBean(PermissionRepository.class)
|
||||||
.findBean(PermissionRepository.class);
|
|
||||||
|
|
||||||
return permissionRepository
|
|
||||||
.findByUuid(id.key.toString())
|
.findByUuid(id.key.toString())
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
.orElseThrow(
|
||||||
.format("No Permission with UUID %s in the database.",
|
() -> new IllegalArgumentException(
|
||||||
id.key.toString())));
|
String.format(
|
||||||
|
"No Permission with UUID %s in the database.",
|
||||||
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -66,4 +73,5 @@ public class PermissionIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof PermissionIdResolver;
|
return resolverType instanceof PermissionIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link Role}s based on their UUIDs for import and export.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class RoleIdResolver implements Serializable, ObjectIdResolver {
|
public class RoleIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = -1651704701257277011L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -44,15 +48,18 @@ public class RoleIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final RoleRepository roleRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(RoleRepository.class);
|
.findBean(RoleRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return roleRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No Role with uuid %s in the database.",
|
"No Role with uuid %s in the database.",
|
||||||
id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,4 +71,5 @@ public class RoleIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof RoleIdResolver;
|
return resolverType instanceof RoleIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,18 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link User}s for import and export based on their UUIDs.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class UserIdResolver implements Serializable, ObjectIdResolver {
|
public class UserIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2541656707906049331L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -45,16 +48,18 @@ public class UserIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
|
return CdiUtil
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
.createCdiUtil()
|
||||||
final UserRepository userRepository = cdiUtil
|
.findBean(UserRepository.class)
|
||||||
.findBean(UserRepository.class);
|
.findByUuid(id.key.toString())
|
||||||
|
.orElseThrow(
|
||||||
return userRepository
|
() -> new IllegalArgumentException(
|
||||||
.findByUuid(id.key.toString())
|
String.format(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
"No User with name %s in the database.",
|
||||||
.format("No User with name %s in the database.",
|
id.key.toString()
|
||||||
id.key.toString())));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -66,4 +71,5 @@ public class UserIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof UserIdResolver;
|
return resolverType instanceof UserIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,41 +26,48 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created the 8/10/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class ApplicationIdResolver implements Serializable, ObjectIdResolver {
|
public class ApplicationIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = 464933392877186401L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey idKey, Object o) {
|
public void bindItem(
|
||||||
|
final ObjectIdGenerator.IdKey idKey,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final ApplicationRepository applicationRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(ApplicationRepository.class);
|
.findBean(ApplicationRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return applicationRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No ccmApplications with uuid %s in the " +
|
"No ccmApplications with uuid %s in the database.",
|
||||||
"database.", id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object o) {
|
public ObjectIdResolver newForDeserialization(final Object object) {
|
||||||
return new ApplicationIdResolver();
|
return new ApplicationIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver objectIdResolver) {
|
public boolean canUseFor(final ObjectIdResolver objectIdResolver) {
|
||||||
return objectIdResolver instanceof ApplicationIdResolver;
|
return objectIdResolver instanceof ApplicationIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,23 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link AssignableTask}s when import or exporting based on
|
||||||
|
* their UUIDs.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Deprecated
|
|
||||||
public class AssignableTaskIdResolver implements Serializable,
|
public class AssignableTaskIdResolver implements Serializable,
|
||||||
ObjectIdResolver {
|
ObjectIdResolver {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4634332219001315735L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -46,15 +50,18 @@ public class AssignableTaskIdResolver implements Serializable,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final AssignableTaskRepository assignableTaskRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(AssignableTaskRepository.class);
|
.findBean(AssignableTaskRepository.class)
|
||||||
|
|
||||||
return assignableTaskRepository
|
|
||||||
.findByUuid(id.key.toString())
|
.findByUuid(id.key.toString())
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
.orElseThrow(
|
||||||
.format("No assignable tasks with uuid %s in the " + "database.",
|
() -> new IllegalArgumentException(
|
||||||
id.key.toString())));
|
String.format(
|
||||||
|
"No assignable tasks with uuid %s in the database.",
|
||||||
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -25,41 +25,49 @@ import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
* Used to resolve {@link TaskComment}s based on their UUIDs when exporting or
|
||||||
* @version created the 9/27/17
|
* import them.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class TaskCommentIdResolver implements Serializable, ObjectIdResolver {
|
public class TaskCommentIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = 1057961565308988397L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
Object pojo) {
|
final ObjectIdGenerator.IdKey id, final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final TaskCommentRepository taskCommentRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(TaskCommentRepository.class);
|
.findBean(TaskCommentRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return taskCommentRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No task comments with uuid %s in the " +
|
"No task comments with uuid %s in the database.",
|
||||||
"database.", id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIdResolver newForDeserialization(Object context) {
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
return new TaskCommentIdResolver();
|
return new TaskCommentIdResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseFor(ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof TaskCommentIdResolver;
|
return resolverType instanceof TaskCommentIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Used to resolve {@link Task}s based on the UUIDs for export or import.
|
||||||
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class TaskIdResolver implements Serializable, ObjectIdResolver {
|
public class TaskIdResolver implements Serializable, ObjectIdResolver {
|
||||||
private static final long serialVersionUID = 6444989953192198987L;
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object object
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -44,15 +48,18 @@ public class TaskIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
return CdiUtil
|
||||||
final TaskRepository taskRepository = cdiUtil
|
.createCdiUtil()
|
||||||
.findBean(TaskRepository.class);
|
.findBean(TaskRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
return taskRepository
|
.orElseThrow(
|
||||||
.findByUuid(id.key.toString())
|
() -> new IllegalArgumentException(
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
String.format(
|
||||||
.format("No tasks with uuid %s in the " +
|
"No tasks with uuid %s in the database.",
|
||||||
"database.", id.key.toString())));
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,4 +71,5 @@ public class TaskIdResolver implements Serializable, ObjectIdResolver {
|
||||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
return resolverType instanceof TaskIdResolver;
|
return resolverType instanceof TaskIdResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,21 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Used to resolve {@link Workflow}s based on their UUIDs for import or export.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @version created on 3/23/17
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class WorkflowIdResolver implements Serializable, ObjectIdResolver {
|
public class WorkflowIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1951611806946125510L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(final ObjectIdGenerator.IdKey id,
|
public void bindItem(
|
||||||
final Object pojo) {
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
final Object pojo
|
||||||
|
) {
|
||||||
// According to the Jackson JavaDoc, this method can be used to keep
|
// According to the Jackson JavaDoc, this method can be used to keep
|
||||||
// track of objects directly in a resolver implementation. We don't need
|
// track of objects directly in a resolver implementation. We don't need
|
||||||
// this here therefore this method is empty.
|
// this here therefore this method is empty.
|
||||||
|
|
@ -48,15 +49,22 @@ public class WorkflowIdResolver implements Serializable, ObjectIdResolver {
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final WorkflowRepository workflowRepository = cdiUtil
|
final WorkflowRepository workflowRepository = cdiUtil.findBean(
|
||||||
.findBean(WorkflowRepository.class);
|
WorkflowRepository.class
|
||||||
|
);
|
||||||
|
|
||||||
return workflowRepository
|
return CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(WorkflowRepository.class)
|
||||||
.findByUuid(id.key.toString())
|
.findByUuid(id.key.toString())
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
.orElseThrow(
|
||||||
.format("No workflows with uuid %s in the "
|
() -> new IllegalArgumentException(
|
||||||
+ "database.",
|
String.format(
|
||||||
id.key.toString())));
|
"No workflows with uuid %s in the database.",
|
||||||
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue