diff --git a/CHANGELOG.md b/CHANGELOG.md index cbdc98008960ef2fdce6402e404d52469cbead41..3cc8832048557c49068fdf498ff6e88efbc1da2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * An openAPI specification of the XML api -* New server configuration option `SERVER_BIND_ADDRESS`, which is the address to listen to. See [server.conf](conf/core/server.conf). +* New server configuration option `SERVER_BIND_ADDRESS`, which is the address to listen to. See + [server.conf](conf/core/server.conf). ### Changed diff --git a/src/main/java/org/caosdb/server/datatype/CaosEnum.java b/src/main/java/org/caosdb/server/datatype/CaosEnum.java index 1040ab9a8114544dfd8a0d5a0a75660be4de5f07..00d8cb167a158a40417e7fddcb9fbe1cf21e7cdb 100644 --- a/src/main/java/org/caosdb/server/datatype/CaosEnum.java +++ b/src/main/java/org/caosdb/server/datatype/CaosEnum.java @@ -61,17 +61,17 @@ class EnumElement implements Comparable<EnumElement> { public class CaosEnum { - final boolean cs; + final boolean case_sensitive; // for string operations public CaosEnum(final String... values) { this(false, values); } - public CaosEnum(final boolean cs, final String... values) { - this.cs = cs; + public CaosEnum(final boolean case_sensitive, final String... values) { + this.case_sensitive = case_sensitive; int index = 0; for (String v : values) { - if (!cs) { + if (!case_sensitive) { v = v.toUpperCase(); } this.values.add(new EnumElement(index++, v)); @@ -82,7 +82,7 @@ public class CaosEnum { public EnumElement valueOf(final String s) { int hash; - if (!this.cs) { + if (!this.case_sensitive) { hash = s.toUpperCase().hashCode(); } else { hash = s.hashCode(); diff --git a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java index a9c74cc1bed1cdd0de26847e629d1264db377753..0b2d7917bf604960738cf305b93d4b50b18d52c8 100644 --- a/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java +++ b/src/main/java/org/caosdb/server/grpc/EntityTransactionServiceImpl.java @@ -45,7 +45,8 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa } /** - * Handle read-only transactions. + * Handle read-only transactions. Of these only one may be a query at the moment, the others must + * be ID retrieves. * * @param request * @return @@ -56,7 +57,7 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa final RetrieveContainer container = new RetrieveContainer( SecurityUtils.getSubject(), getTimestamp(), getSRID(), new HashMap<>()); - FileDownload file_download = null; + FileDownload fileDownload = null; for (final TransactionRequest sub_request : request.getRequestsList()) { if (sub_request.getWrappedRequestsCase() != WrappedRequestsCase.RETRIEVE_REQUEST) { @@ -65,20 +66,20 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa + sub_request.getWrappedRequestsCase().name() + " in a read-only request."); } - final boolean fileDownload = sub_request.getRetrieveRequest().getRegisterFileDownload(); - if (sub_request.getRetrieveRequest().hasQuery() + final boolean isFileDownload = sub_request.getRetrieveRequest().getRegisterFileDownload(); + if (sub_request.getRetrieveRequest().hasQuery() // Retrieves are either queries... && !sub_request.getRetrieveRequest().getQuery().getQuery().isBlank()) { final String query = sub_request.getRetrieveRequest().getQuery().getQuery(); container.getFlags().put("query", query); - if (fileDownload) { + if (isFileDownload) { container.getFlags().put("download_files", "true"); } - } else { + } else { // or ID retrieves. final String id = sub_request.getRetrieveRequest().getId(); if (!id.isBlank()) { try { final RetrieveEntity entity = new RetrieveEntity(grpcToCaosdb.getId(id)); - if (fileDownload) { + if (isFileDownload) { entity.setFlag("download_files", "true"); } container.add(entity); @@ -102,13 +103,13 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa final EntityResponse.Builder entityResponse = caosdbToGrpc.convert(entity); if ((download_files_container || entity.getFlags().containsKey("download_files")) && entity.hasFileProperties()) { - if (file_download == null) { - file_download = fileTransmissionService.registerFileDownload(null); + if (fileDownload == null) { + fileDownload = fileTransmissionService.registerFileDownload(null); } entity.getFileProperties().retrieveFromFileSystem(); entityResponse.setDownloadId( fileTransmissionService.registerFileDownload( - file_download.getId(), entity.getFileProperties())); + fileDownload.getId(), entity.getFileProperties())); } builder .addResponsesBuilder() @@ -116,16 +117,15 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa } } - // Add those entities which have not been retrieved because the have a string id + // Add those entities which have not been retrieved because they have a string id for (final TransactionRequest sub_request : request.getRequestsList()) { final String id = sub_request.getRetrieveRequest().getId(); if (!id.isBlank()) { try { grpcToCaosdb.getId(id); } catch (final NumberFormatException e) { - // ID wasn't an integer - the server doesn't support string id's yet, so that entity - // cannot - // exist. + // ID wasn't an integer - the server doesn't support string ids yet, so that entity + // cannot exist. builder.addResponses( TransactionResponse.newBuilder() .setRetrieveResponse( @@ -154,6 +154,8 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa /** * Handle all entity transactions. * + * <p>Currently either all requests must be read-only/retrieve requests, or none of the requests. + * * @param request * @return * @throws Exception @@ -161,8 +163,9 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa public MultiTransactionResponse transaction(final MultiTransactionRequest request) throws Exception { if (request.getRequestsCount() > 0) { - // we only test the first request and raise errors when subsequent sub-transactions do not - // fit. + // We only test the first request and raise errors when subsequent sub-transactions do not fit + // into the retrieve context. Currently this means that either all or none of the requests + // must be retrieve requests. final WrappedRequestsCase requestCase = request.getRequests(0).getWrappedRequestsCase(); switch (requestCase) { case RETRIEVE_REQUEST: @@ -219,7 +222,7 @@ public class EntityTransactionServiceImpl extends EntityTransactionServiceImplBa try { final UpdateEntity entity = new UpdateEntity( - grpcToCaosdb.getId(updateEntity.getId()), + grpcToCaosdb.getId(updateEntity.getId()), // ID is not handled by grpc convert grpcToCaosdb.convert(updateEntity.getRole())); entity.setName(updateEntity.getName().isEmpty() ? null : updateEntity.getName()); grpcToCaosdb.convert(updateEntity, entity); diff --git a/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java b/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java index 302800711262ace87513eee9d5712420a4e496f5..c2007bebd52f29ce8d1a02fe9e0fcd913a8df798 100644 --- a/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java +++ b/src/main/java/org/caosdb/server/grpc/GrpcToCaosDBConverters.java @@ -70,6 +70,10 @@ public class GrpcToCaosDBConverters { return new GenericValue(valString); } + /** + * Set the content of {@code entity} to that of the grpc message object {@code from}. Also return + * {@code entity} at the end. + */ public EntityInterface convert(final Entity from, final EntityInterface entity) { entity.setName(from.getName().isEmpty() ? null : from.getName()); entity.setDescription(from.getDescription().isBlank() ? null : from.getDescription()); @@ -209,8 +213,8 @@ public class GrpcToCaosDBConverters { final StatementStatus defaultImportance) { final Collection<Property> result = new LinkedList<>(); propertiesList.forEach( - e -> { - result.add(convert(e, defaultImportance)); + prop -> { + result.add(convert(prop, defaultImportance)); }); return result; } diff --git a/src/main/java/org/caosdb/server/jobs/core/TestMail.java b/src/main/java/org/caosdb/server/jobs/core/TestMail.java index 210a9f59b879529f5f96954250556e88f60454be..793e6fe211f18c2d576501597c1189dac2444d46 100644 --- a/src/main/java/org/caosdb/server/jobs/core/TestMail.java +++ b/src/main/java/org/caosdb/server/jobs/core/TestMail.java @@ -43,12 +43,12 @@ public class TestMail extends FlagJob { CaosDBServer.getServerProperty(ServerProperties.KEY_NO_REPLY_EMAIL); @Override - protected void job(final String value) { - if (CaosDBServer.isDebugMode() && value != null) { - if (Utils.isRFC822Compliant(value)) { - final Mail m = new Mail(NAME, EMAIL, null, value, "Test mail", "This is a test mail."); + protected void job(final String recipient) { + if (CaosDBServer.isDebugMode() && recipient != null) { + if (Utils.isRFC822Compliant(recipient)) { + final Mail m = new Mail(NAME, EMAIL, null, recipient, "Test mail", "This is a test mail."); m.send(); - getContainer().addMessage(new Message("A mail has been send to " + value)); + getContainer().addMessage(new Message("A mail has been sent to " + recipient)); } else { getContainer().addMessage(ServerMessages.EMAIL_NOT_WELL_FORMED); }