Skip to content
Snippets Groups Projects
Commit af10a211 authored by OZGCloud's avatar OZGCloud
Browse files

cleanups and api optimization

parent 67998d8b
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package de.itvsh.kop.common.binaryfile; package de.itvsh.kop.common.binaryfile;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import de.itvsh.kop.common.datatype.StringBasedValue; import de.itvsh.kop.common.datatype.StringBasedValue;
...@@ -42,6 +43,9 @@ public class FileId extends StringBasedValue { ...@@ -42,6 +43,9 @@ public class FileId extends StringBasedValue {
} }
public static FileId from(String fileId) { public static FileId from(String fileId) {
if (Objects.nonNull(fileId)) {
return new FileId(fileId); return new FileId(fileId);
} }
return null;
}
} }
\ No newline at end of file
...@@ -37,6 +37,11 @@ import lombok.NoArgsConstructor; ...@@ -37,6 +37,11 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
public class GrpcUtil { public class GrpcUtil {
public static final Key<byte[]> HEADER_KEY_USER_ID = createKeyOf("USER_ID-bin");
public static final Key<byte[]> HEADER_KEY_CLIENT_NAME = createKeyOf("CLIENT_NAME-bin");
public static final Key<byte[]> HEADER_KEY_REQUEST_ID = createKeyOf("REQUEST_ID-bin");
public static Key<String> keyOfString(String key) { public static Key<String> keyOfString(String key) {
return Key.of(key, Metadata.ASCII_STRING_MARSHALLER); return Key.of(key, Metadata.ASCII_STRING_MARSHALLER);
} }
...@@ -45,10 +50,12 @@ public class GrpcUtil { ...@@ -45,10 +50,12 @@ public class GrpcUtil {
return Key.of(key, Metadata.BINARY_BYTE_MARSHALLER); return Key.of(key, Metadata.BINARY_BYTE_MARSHALLER);
} }
public static String getFromHeaders(String key, Metadata headers) { public static Optional<String> getFromHeaders(String key, Metadata headers) {
return Optional.ofNullable(headers.get(createKeyOf(key))) return getFromHeaders(createKeyOf(key), headers);
.map(GrpcUtil::byteToString) }
.orElse(null);
public static Optional<String> getFromHeaders(Key<byte[]> key, Metadata headers) {
return Optional.ofNullable(headers.get(key)).map(GrpcUtil::byteToString);
} }
public static Collection<String> getCollection(String key, Metadata headers) { public static Collection<String> getCollection(String key, Metadata headers) {
...@@ -64,4 +71,5 @@ public class GrpcUtil { ...@@ -64,4 +71,5 @@ public class GrpcUtil {
private static String byteToString(byte[] bytes) { private static String byteToString(byte[] bytes) {
return new String(bytes, StandardCharsets.UTF_8); return new String(bytes, StandardCharsets.UTF_8);
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment