Skip to content

Commit b3b9c8c

Browse files
committed
remove some 'log & throw' stupidity
1 parent 4420f90 commit b3b9c8c

File tree

9 files changed

+50
-122
lines changed

9 files changed

+50
-122
lines changed

api/src/main/java/org/fairdatapipeline/api/Data_product_read.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
import org.fairdatapipeline.dataregistry.content.RegistryStorage_location;
1414
import org.fairdatapipeline.dataregistry.content.RegistryStorage_root;
1515
import org.fairdatapipeline.file.CleanableFileChannel;
16-
import org.slf4j.Logger;
17-
import org.slf4j.LoggerFactory;
1816

1917
/**
2018
* Data_product_read is created by Coderun: {@link Coderun#get_dp_for_read(String)}
2119
*
2220
* <p>Upon {@link Coderun#close()} it will register its components in the coderun.
2321
*/
2422
public class Data_product_read extends Data_product {
25-
private static final Logger logger = LoggerFactory.getLogger(Data_product_read.class);
2623
private boolean hash_checked = false;
2724

2825
Data_product_read(String dataProduct_name, Coderun coderun) {
@@ -33,56 +30,48 @@ void populate_data_product() {
3330
// called from the constructor
3431
this.registryData_product = this.getRegistryData_product();
3532
if (this.registryData_product == null) {
36-
String msg =
33+
throw (new RegistryObjectNotfoundException(
3734
"Trying to read from non-existing data_product "
3835
+ this.actualDataProduct_name
3936
+ "; NS "
4037
+ this.registryNamespace.getName()
4138
+ "; version "
42-
+ version;
43-
logger.error(msg);
44-
throw (new RegistryObjectNotfoundException(msg));
39+
+ version));
4540
}
4641
this.registryObject =
4742
(RegistryObject)
4843
coderun.restClient.get(RegistryObject.class, this.registryData_product.getObject());
4944
if (this.registryObject == null) {
50-
String msg =
45+
throw (new RegistryObjectNotfoundException(
5146
"couldn't retrieve the fdpObject for this READ dp "
5247
+ this.givenDataProduct_name
5348
+ " ("
5449
+ this.actualDataProduct_name
55-
+ ")";
56-
logger.error(msg);
57-
throw (new RegistryObjectNotfoundException(msg));
50+
+ ")"));
5851
}
5952
this.registryStorage_location =
6053
(RegistryStorage_location)
6154
coderun.restClient.get(
6255
RegistryStorage_location.class, this.registryObject.getStorage_location());
6356
if (this.registryStorage_location == null) {
64-
String msg =
57+
throw (new RegistryObjectNotfoundException(
6558
"Couldn't retrieve the StorageLocation for this READ dp "
6659
+ this.givenDataProduct_name
6760
+ " ("
6861
+ this.actualDataProduct_name
69-
+ ")";
70-
logger.error(msg);
71-
throw (new RegistryObjectNotfoundException(msg));
62+
+ ")"));
7263
}
7364
this.registryStorage_root =
7465
(RegistryStorage_root)
7566
coderun.restClient.get(
7667
RegistryStorage_root.class, this.registryStorage_location.getStorage_root());
7768
if (this.registryStorage_root == null) {
78-
String msg =
69+
throw (new RegistryObjectNotfoundException(
7970
"Couldn't retrieve the StorageRoot for this READ dp "
8071
+ this.givenDataProduct_name
8172
+ " ("
8273
+ this.actualDataProduct_name
83-
+ ")";
84-
logger.error(msg);
85-
throw (new RegistryObjectNotfoundException(msg));
74+
+ ")"));
8675
}
8776
this.filePath =
8877
this.registryStorage_root
@@ -102,19 +91,15 @@ RegistryNamespace getRegistryNamespace(String namespace_name) {
10291
// for a READ dp we must have the namespace from the config or we will have to give up
10392
RegistryNamespace ns = super.getRegistryNamespace(namespace_name);
10493
if (ns == null) {
105-
String msg = "Can't find the namespace " + namespace_name;
106-
logger.error(msg);
107-
throw (new RegistryObjectNotfoundException(msg));
94+
throw (new RegistryObjectNotfoundException("Can't find the namespace " + namespace_name));
10895
}
10996
return ns;
11097
}
11198

11299
ImmutableConfigItem getConfigItem(String dataProduct_name) {
113100
ImmutableConfigItem configItem = super.getConfigItem(dataProduct_name);
114101
if (configItem == null) {
115-
String msg = "dataProduct " + dataProduct_name + " not found in config";
116-
logger.error(msg);
117-
throw (new ConfigException(msg));
102+
throw (new ConfigException("dataProduct " + dataProduct_name + " not found in config"));
118103
}
119104
return configItem;
120105
}

api/src/main/java/org/fairdatapipeline/api/Data_product_write.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public class Data_product_write extends Data_product {
3939
void populate_data_product() {
4040
// called from the constructor
4141
if (this.getRegistryData_product() != null) {
42-
String msg =
42+
throw (new IllegalActionException(
4343
"You can't write to a Data Product that already exists: "
4444
+ this.actualDataProduct_name
4545
+ ", version "
4646
+ this.version
4747
+ ", namespace: "
48-
+ this.namespace_name;
49-
logger.error(msg);
50-
throw (new IllegalActionException(msg));
48+
+ this.namespace_name));
5149
}
5250
File_type file_type = new File_type(this.extension, coderun.restClient);
5351

@@ -82,9 +80,8 @@ RegistryNamespace getRegistryNamespace(String namespace_name) {
8280
if (ns == null) {
8381
ns = (RegistryNamespace) coderun.restClient.post(new RegistryNamespace(namespace_name));
8482
if (ns == null) {
85-
String msg = "Failed to create in registry: namespace '" + namespace_name + "'";
86-
logger.error(msg);
87-
throw (new RegistryException(msg));
83+
throw (new RegistryException(
84+
"Failed to create in registry: namespace '" + namespace_name + "'"));
8885
}
8986
}
9087
return ns;
@@ -108,9 +105,7 @@ ImmutableConfigItem getConfigItem(String dataProduct_name) {
108105
.orElse(null);
109106
}
110107
if (configItem == null) {
111-
String msg = "DataProduct " + dataProduct_name + " not found in config";
112-
logger.error(msg);
113-
throw (new ConfigException(msg));
108+
throw (new ConfigException("DataProduct " + dataProduct_name + " not found in config"));
114109
}
115110
return configItem;
116111
}
@@ -224,11 +219,9 @@ void stolo_obj_and_dp_to_registry() {
224219
RegistryStorage_location sl =
225220
(RegistryStorage_location) this.coderun.restClient.post(this.registryStorage_location);
226221
if (sl == null) {
227-
String msg =
222+
throw (new RegistryException(
228223
"Failed to create in registry: new storage location "
229-
+ this.registryStorage_location.getPath();
230-
logger.error(msg);
231-
throw (new RegistryException(msg));
224+
+ this.registryStorage_location.getPath()));
232225
} else {
233226
this.registryStorage_location = sl;
234227
}
@@ -237,19 +230,16 @@ void stolo_obj_and_dp_to_registry() {
237230
this.registryObject.setStorage_location(this.registryStorage_location.getUrl());
238231
final RegistryObject o = (RegistryObject) this.coderun.restClient.post(this.registryObject);
239232
if (o == null) {
240-
String msg = "Failed to create in registry: Object " + this.registryObject.getDescription();
241-
logger.error(msg);
242-
throw (new RegistryException(msg));
233+
throw (new RegistryException(
234+
"Failed to create in registry: Object " + this.registryObject.getDescription()));
243235
}
244236
this.registryObject = o;
245237
this.registryData_product.setObject(o.getUrl());
246238
RegistryData_product dp =
247239
(RegistryData_product) this.coderun.restClient.post(this.registryData_product);
248240
if (dp == null) {
249-
String msg =
250-
"Failed to create in registry: Data_product " + this.registryData_product.getName();
251-
logger.error(msg);
252-
throw (new RegistryException(msg));
241+
throw (new RegistryException(
242+
"Failed to create in registry: Data_product " + this.registryData_product.getName()));
253243
}
254244
this.registryData_product = dp;
255245
}

api/src/main/java/org/fairdatapipeline/api/FileObject.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import java.util.List;
44
import org.fairdatapipeline.dataregistry.content.RegistryObject;
55
import org.fairdatapipeline.dataregistry.restclient.APIURL;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
86

97
/**
108
* A new registryObject with given storage_location, description, authors, file_type. Used for
119
* Submission Script, Code Repo, Config File, which can have issues raised on.
1210
*/
1311
public class FileObject {
14-
private static final Logger logger = LoggerFactory.getLogger(FileObject.class);
1512
Coderun coderun;
1613
RegistryObject o;
1714

@@ -40,9 +37,8 @@ public class FileObject {
4037
this.o.setAuthors(authors);
4138
this.o = (RegistryObject) coderun.restClient.post(this.o);
4239
if (this.o == null) {
43-
String msg = "Failed to create Object in registry: " + storage_location.getUrl();
44-
logger.error(msg);
45-
throw (new RegistryException(msg));
40+
throw (new RegistryException(
41+
"Failed to create Object in registry: " + storage_location.getUrl()));
4642
}
4743
}
4844

@@ -71,9 +67,7 @@ public class FileObject {
7167
*/
7268
public void raise_issue(String description, Integer severity) {
7369
if (o.getComponents().isEmpty()) {
74-
String msg = "Object component not found.";
75-
logger.error(msg);
76-
throw (new IllegalActionException(msg));
70+
throw (new IllegalActionException("Object component not found."));
7771
}
7872
Issue i = this.coderun.raise_issue(description, severity);
7973
i.add_registryObject_component(getWholeObjectComponentUrl());

api/src/main/java/org/fairdatapipeline/api/File_type.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
import org.fairdatapipeline.dataregistry.content.RegistryFile_type;
55
import org.fairdatapipeline.dataregistry.restclient.APIURL;
66
import org.fairdatapipeline.dataregistry.restclient.RestClient;
7-
import org.slf4j.Logger;
8-
import org.slf4j.LoggerFactory;
97

108
/** Encapsulates the registryFile_type object */
119
class File_type {
12-
private static final Logger logger = LoggerFactory.getLogger(File_type.class);
1310
RegistryFile_type registryFile_type;
1411

1512
/**
@@ -28,9 +25,7 @@ class File_type {
2825
this.registryFile_type =
2926
(RegistryFile_type) restClient.post(new RegistryFile_type(extension, extension));
3027
if (this.registryFile_type == null) {
31-
String msg = "Failed to create File_type in Registry: " + extension;
32-
logger.error(msg);
33-
throw (new RegistryException(msg));
28+
throw (new RegistryException("Failed to create File_type in Registry: " + extension));
3429
}
3530
}
3631
}

api/src/main/java/org/fairdatapipeline/api/Issue.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.util.List;
66
import org.fairdatapipeline.dataregistry.content.RegistryIssue;
77
import org.fairdatapipeline.dataregistry.restclient.APIURL;
8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
108

119
/**
1210
* An issue that can be raised with objects or their components.
@@ -49,7 +47,6 @@
4947
* </blockquote>
5048
*/
5149
public class Issue {
52-
private static final Logger logger = LoggerFactory.getLogger(Issue.class);
5350
RegistryIssue registryIssue;
5451
String description;
5552
Integer severity;

api/src/main/java/org/fairdatapipeline/api/Object_component_read.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import org.fairdatapipeline.distribution.Distribution;
77
import org.fairdatapipeline.file.CleanableFileChannel;
88
import org.fairdatapipeline.parameters.ReadComponent;
9-
import org.slf4j.Logger;
10-
import org.slf4j.LoggerFactory;
119

1210
/**
1311
* This represents an object_component to read from (or raise issues with) An object_component
@@ -16,7 +14,6 @@
1614
* is not enforced at the moment.
1715
*/
1816
public class Object_component_read extends Object_component {
19-
private static final Logger logger = LoggerFactory.getLogger(Object_component_read.class);
2017

2118
Object_component_read(Data_product_read dp, String component_name) {
2219
super(dp, component_name);
@@ -29,14 +26,12 @@ public class Object_component_read extends Object_component {
2926
protected void populate_component() {
3027
this.registryObject_component = this.retrieveObject_component();
3128
if (this.registryObject_component == null) {
32-
String msg =
29+
throw (new RegistryObjectNotfoundException(
3330
"Object Component '"
3431
+ this.component_name
3532
+ "' for Object "
3633
+ this.dp.registryObject.get_id().toString()
37-
+ " not found in registry.";
38-
logger.error(msg);
39-
throw (new RegistryObjectNotfoundException(msg));
34+
+ " not found in registry."));
4035
}
4136
}
4237

@@ -47,9 +42,8 @@ protected void populate_component() {
4742
*/
4843
public Path readLink() {
4944
if (!this.whole_object) {
50-
String msg = "You shouldn't try to read directly from a Data Product with named components.";
51-
logger.error(msg);
52-
throw (new IllegalActionException(msg));
45+
throw (new IllegalActionException(
46+
"You shouldn't try to read directly from a Data Product with named components."));
5347
}
5448
this.been_used = true;
5549
return this.dp.getFilePath();
@@ -63,9 +57,8 @@ public Path readLink() {
6357
*/
6458
public CleanableFileChannel readFileChannel() throws IOException {
6559
if (!this.whole_object) {
66-
String msg = "You shouldn't try to read directly from a Data Product with named components.";
67-
logger.error(msg);
68-
throw (new IllegalActionException(msg));
60+
throw (new IllegalActionException(
61+
"You shouldn't try to read directly from a Data Product with named components."));
6962
}
7063
this.been_used = true;
7164
return this.getFileChannel();
@@ -82,9 +75,7 @@ public Number readEstimate() {
8275
data =
8376
dp.coderun.parameterDataReader.read(fileChannel, this.registryObject_component.getName());
8477
} catch (IOException e) {
85-
String msg = "readEstimate() -- IOException trying to read from file";
86-
logger.error(msg + "\n" + e);
87-
throw (new RuntimeException(msg, e));
78+
throw (new RuntimeException("readEstimate() -- IOException trying to read from file", e));
8879
}
8980
return data.getEstimate();
9081
}
@@ -99,9 +90,8 @@ public Distribution readDistribution() {
9990
try (CleanableFileChannel fileChannel = this.getFileChannel()) {
10091
data = this.dp.coderun.parameterDataReader.read(fileChannel, this.component_name);
10192
} catch (IOException e) {
102-
String msg = "readDistribution() -- IOException trying to read from file.";
103-
logger.error(msg + "\n" + e);
104-
throw (new RuntimeException(msg, e));
93+
throw (new RuntimeException(
94+
"readDistribution() -- IOException trying to read from file.", e));
10595
}
10696
return data.getDistribution();
10797
}
@@ -116,9 +106,7 @@ public List<Number> readSamples() {
116106
try (CleanableFileChannel fileChannel = this.getFileChannel()) {
117107
data = this.dp.coderun.parameterDataReader.read(fileChannel, this.component_name);
118108
} catch (IOException e) {
119-
String msg = "readSamples() -- IOException trying to read from file.";
120-
logger.error(msg + "\n" + e);
121-
throw (new RuntimeException(msg, e));
109+
throw (new RuntimeException("readSamples() -- IOException trying to read from file.", e));
122110
}
123111
return data.getSamples();
124112
}

0 commit comments

Comments
 (0)