Skip to content

Commit

Permalink
Remove private getters
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Apr 20, 2024
1 parent f7f508a commit b909d71
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.ApplicationPath;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class ResourceConfig extends org.glassfish.jersey.server.ResourceConfig {
*/
@Inject
public ResourceConfig() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
final Class<? extends BinderFactory> binderClass = Class.forName(getBindingFactory())
final Class<? extends BinderFactory> binderClass = Class.forName(bindingFactory)
.asSubclass(BinderFactory.class);
LOG.info("Application resource binder is '{}'", binderClass.getCanonicalName());
final BinderFactory binderFactory = binderClass.newInstance();
Expand All @@ -72,9 +71,4 @@ public ResourceConfig() throws ClassNotFoundException, InstantiationException, I
// Call post-registration hook to allow for additional registration
binderFactory.afterRegistration(this);
}

@NotNull
private String getBindingFactory() {
return bindingFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public Response uploadFile(
final @NotNull @FormDataParam("file") FormDataContentDisposition fileMetaData
) {
final File file = new File(MetaData.of(fileMetaData), fileContent);
final String fileId = getFileStore().upload(file);
getMetaStore().saveMetaData(fileId, file.getMetaData());
final String fileId = fileStore.upload(file);
metaStore.saveMetaData(fileId, file.getMetaData());
return Response
.status(Response.Status.CREATED)
.entity(Collections.singletonMap(FILE_ID, fileId))
Expand All @@ -115,29 +115,19 @@ public Response uploadFile(
public Response downloadFile(@QueryParam(FILE_ID) final String fileId) {
return Response
.ok(
getFileStore().download(Objects.requireNonNull(fileId)),
fileStore.download(Objects.requireNonNull(fileId)),
MediaType.APPLICATION_OCTET_STREAM
)
.header(
"content-disposition",
String.format(
"attachment; filename = %s",
((Map<?, ?>) ((Map<?, ?>) getMetaStore()
((Map<?, ?>) ((Map<?, ?>) metaStore
.getMetaData(fileId, Collections.singletonList(MetaData.FILE_NAME))
.toSpecification().get("data")).get("metaData"))
.get(MetaData.FILE_NAME).toString()
)
)
.build();
}

@NotNull
private FileStore getFileStore() {
return fileStore;
}

@NotNull
private MetaStore getMetaStore() {
return metaStore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public MetaServlet(final @NotNull MetaStore metaStore, final @NotNull JsonDocume
public Response get(final @NotNull @QueryParam("query") String query) {
return Response
.status(Response.Status.OK)
.entity(getMetaStore().executeNative(Objects.requireNonNull(query)))
.entity(metaStore.executeNative(Objects.requireNonNull(query)))
.build();
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public Response get(final @NotNull @QueryParam("query") String query) {
public Response post(final @NotNull String graphQLDocument) {
Objects.requireNonNull(graphQLDocument);

final List<String> requestedMetadataFields = getJsonDocumentParser().getFields(graphQLDocument);
final List<String> requestedMetadataFields = jsonDocumentParser.getFields(graphQLDocument);
if (requestedMetadataFields.isEmpty()) {
LOG.error(ErrorMessageFormat.INVALID_GRAPHQL_REQUEST.logFormat("No metadata field found", graphQLDocument));
throw new IllegalArgumentException(
Expand All @@ -133,21 +133,11 @@ public Response post(final @NotNull String graphQLDocument) {
return Response
.status(Response.Status.OK)
.entity(
getMetaStore().getMetaData(
getJsonDocumentParser().getFileId(graphQLDocument),
metaStore.getMetaData(
jsonDocumentParser.getFileId(graphQLDocument),
requestedMetadataFields
)
)
.build();
}

@NotNull
private MetaStore getMetaStore() {
return metaStore;
}

@NotNull
private JsonDocumentParser getJsonDocumentParser() {
return jsonDocumentParser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import jakarta.validation.constraints.NotNull;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.NotThreadSafe;

Expand Down Expand Up @@ -68,13 +67,8 @@ public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) {
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
);

getMetaDataByFileId().put(fileId, newMetaData);
metaDataByFileId.put(fileId, newMetaData);

return newMetaData;
}

@NotNull
private Map<String, MetaData> getMetaDataByFileId() {
return metaDataByFileId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public TestQueryDataFetcher(final @NotNull Map<String, MetaData> metaDataByFileI
@Override
public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) {
final String fileId = dataFetchingEnvironment.getArgument(FILE_ID);
return getMetaDataByFileId().get(fileId);
}

@NotNull
private Map<String, MetaData> getMetaDataByFileId() {
return metaDataByFileId;
return metaDataByFileId.get(fileId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public TestFileStore(

@Override
public String upload(final File file) {
final String fileId = getFileIdGenerator().apply(file);
getFileByFileId().put(
getFileIdGenerator().apply(file),
final String fileId = fileIdGenerator.apply(file);
fileByFileId.put(
fileIdGenerator.apply(file),
new BufferedReader(new InputStreamReader(file.getFileContent()))
.lines().collect(Collectors.joining("\n"))
);
Expand All @@ -92,16 +92,6 @@ public String upload(final File file) {

@Override
public InputStream download(final String fileId) {
return new ByteArrayInputStream(getFileByFileId().get(fileId).getBytes());
}

@NotNull
private Map<String, String> getFileByFileId() {
return fileByFileId;
}

@NotNull
private FileIdGenerator getFileIdGenerator() {
return fileIdGenerator;
return new ByteArrayInputStream(fileByFileId.get(fileId).getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import jakarta.validation.constraints.NotNull;

import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -61,7 +60,7 @@ public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) throw
final String fileType = dataFetchingEnvironment.getArgument(MetaData.FILE_TYPE);

try (
Connection connection = getDataSource().getConnection();
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(META_DATA_PERSIST_QUERY_TEMPLATE)
) {
statement.setString(1, fileId);
Expand All @@ -77,9 +76,4 @@ public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) throw
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
);
}

@NotNull
private DataSource getDataSource() {
return dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) throw
final String fileId = dataFetchingEnvironment.getArgument(FILE_ID);
final ResultSet resultSet;
try (
Connection connection = getDataSource().getConnection();
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(META_DATA_FETCH_QUERY_TEMPLATE)
) {
statement.setString(1, fileId);
Expand Down Expand Up @@ -100,9 +100,4 @@ public MetaData get(final DataFetchingEnvironment dataFetchingEnvironment) throw
return metaData;
}
}

@NotNull
private DataSource getDataSource() {
return dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public SwiftFileStore(final @NotNull Account account, final @NotNull FileIdGener
@Override
public String upload(final File file) {
Objects.requireNonNull(file);
final String fileId = getFileIdGenerator().apply(file);
final String fileId = fileIdGenerator.apply(file);

getAccount()
account
.getContainer(DEFAULT_CONTAINER)
.getObject(fileId)
.uploadObject(file.getFileContent());
Expand All @@ -80,19 +80,9 @@ public String upload(final File file) {

@Override
public InputStream download(final String fileId) {
return getAccount()
return account
.getContainer(DEFAULT_CONTAINER)
.getObject(Objects.requireNonNull(fileId))
.downloadObjectAsInputStream();
}

@NotNull
private Account getAccount() {
return account;
}

@NotNull
private FileIdGenerator getFileIdGenerator() {
return fileIdGenerator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private GraphQLMetaStore(@NotNull final GraphQL graphQL, @NotNull final GraphQLQ

@Override
public ExecutionResult executeNative(final String query) {
return getGraphQL().execute(Objects.requireNonNull(query));
return graphQL.execute(Objects.requireNonNull(query));
}

@Override
Expand All @@ -104,30 +104,20 @@ public ExecutionResult getMetaData(final String fileId, final List<String> metad
throw new IllegalArgumentException(EMPTY_LIST.format());
}

return getGraphQL().execute(
return graphQL.execute(
ExecutionInput.newExecutionInput()
.query(getGraphQLQueryProvider().query(fileId, metadataFields))
.query(graphQLQueryProvider.query(fileId, metadataFields))
.build()
);
}

@Override
public void saveMetaData(final String fileId, final MetaData metaData) {
getGraphQL().execute(
getGraphQLQueryProvider().mutation(
graphQL.execute(
graphQLQueryProvider.mutation(
Objects.requireNonNull(fileId),
Objects.requireNonNull(metaData)
)
);
}

@NotNull
private GraphQL getGraphQL() {
return graphQL;
}

@NotNull
private GraphQLQueryProvider getGraphQLQueryProvider() {
return graphQLQueryProvider;
}
}
7 changes: 1 addition & 6 deletions docs/docs/filestores/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class S3FileStore implements FileStore {
public String upload(final File file) {
final String fileId = fileIdGenerator.apply(file);

getS3client().putObject(
s3client.putObject(
file.getMetaData().getFileType().name(),
fileId,
file.getFileContent(),
Expand All @@ -117,11 +117,6 @@ public class S3FileStore implements FileStore {
public InputStream download(final String fileId) {
return getS3client().getObject(...);
}

@NotNull
private AmazonS3 getS3client() {
return s3client;
}
}
```

Expand Down

0 comments on commit b909d71

Please sign in to comment.