Skip to content

Commit 8e3ccc1

Browse files
committed
one format for the errors
1 parent b731b4a commit 8e3ccc1

11 files changed

Lines changed: 36 additions & 32 deletions

File tree

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/EntityFactory.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public <T> Page<T> createPage(final Netlicensing netlicensing, final Class<T> en
203203
try {
204204
((Visitable) entity).accept(new LinkedEntitiesPopulator(linkedEntities));
205205
} catch (final Exception e) {
206-
throw new ConversionException("Error processing linked entities", e);
206+
throw new ConversionException("Error processing linked entities.", e);
207207
}
208208
}
209209
}
@@ -216,7 +216,7 @@ public <T> Page<T> createPage(final Netlicensing netlicensing, final Class<T> en
216216
netlicensing.getItems().getTotalitems(),
217217
netlicensing.getItems().getHasnext());
218218
} else {
219-
throw new WrongResponseFormatException("Service response is not a page response");
219+
throw new WrongResponseFormatException("Service response is not a page response.");
220220
}
221221
}
222222

@@ -233,21 +233,24 @@ private <T> Converter<Item, T> converterFor(final Class<T> entityClass) {
233233
try {
234234
converter = (Converter<Item, T>) getConvertersCache().get(entityClass);
235235
} catch (final ClassCastException e) {
236-
throw new RuntimeException("Wrong converter type found for entity class " + entityClass.getCanonicalName());
236+
throw new RuntimeException(
237+
"Wrong converter type found for entity class " + entityClass.getCanonicalName() + ".");
237238
}
238239
if (converter == null) {
239240
final Class<?> converterClass = entityToConverterMap.get(entityClass);
240241
if (converterClass == null) {
241242
throw new IllegalArgumentException("No converter is found for entity of class "
242-
+ entityClass.getCanonicalName());
243+
+ entityClass.getCanonicalName() + ".");
243244
}
244245
try {
245246
converter = (Converter<Item, T>) converterClass.newInstance();
246247
getConvertersCache().put(entityClass, converter);
247248
} catch (final InstantiationException e) {
248-
throw new RuntimeException("Can not instantiate converter of class " + converterClass.getCanonicalName());
249+
throw new RuntimeException(
250+
"Can not instantiate converter of class " + converterClass.getCanonicalName() + ".");
249251
} catch (final IllegalAccessException e) {
250-
throw new RuntimeException("Can not instantiate converter of class " + converterClass.getCanonicalName());
252+
throw new RuntimeException(
253+
"Can not instantiate converter of class " + converterClass.getCanonicalName() + ".");
251254
}
252255
}
253256
return converter;
@@ -273,7 +276,7 @@ private Item findSuitableItemOfType(final Netlicensing netlicensing, final Class
273276
}
274277
}
275278
throw new WrongResponseFormatException("Service response doesn't contain item of type "
276-
+ type.getCanonicalName());
279+
+ type.getCanonicalName() + ".");
277280
}
278281

279282
/**
@@ -307,7 +310,7 @@ private Class<?> getEntityClassByItemType(final Item item) throws WrongResponseF
307310
return entityClass;
308311
}
309312
}
310-
throw new WrongResponseFormatException("Service response contains unexpected item type " + itemType);
313+
throw new WrongResponseFormatException("Service response contains unexpected item type " + itemType + ".");
311314
}
312315

313316
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/ProductDiscountImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void setStringAmount(final String amount) {
118118
setAmountPercent(DatatypeConverter.parseDecimal(amount.substring(0, amount.length() - 1)));
119119
} catch (final NumberFormatException e) {
120120
throw new IllegalArgumentException(
121-
"Format for discount amount in percent is not correct, expected numeric format");
121+
"Format for discount amount in percent is not correct, expected numeric format.");
122122
}
123123
} else {
124124
final Money amountFix = Money.convertPrice(amount, Currency.EUR.value());

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Money.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ public static Money convertPrice(final String rawPrice, final String rawCurrency
5858
target.setAmount(DatatypeConverter.parseDecimal(rawPrice));
5959
} catch (final NumberFormatException e) {
6060
throw new IllegalArgumentException("'" + Constants.PRICE
61-
+ "' format is not correct, expected '0.00' format");
61+
+ "' format is not correct, expected '0.00' format.");
6262
}
6363
if (StringUtils.isNotBlank(rawCurrency)) {
6464
if (Currency.parseValueSafe(rawCurrency) == null) {
65-
throw new IllegalArgumentException("Unsupported currency!");
65+
throw new IllegalArgumentException("Unsupported currency.");
6666
}
6767
target.setCurrencyCode(rawCurrency);
6868
} else {
6969
throw new IllegalArgumentException("'" + Constants.PRICE + "' field must be accompanied with the '"
70-
+ Constants.CURRENCY + "' field");
70+
+ Constants.CURRENCY + "' field.");
7171
}
7272
} else { // 'price' is not provided
7373
if (StringUtils.isNotBlank(rawCurrency)) {
7474
throw new IllegalArgumentException("'" + Constants.CURRENCY + "' field can not be used without the '"
75-
+ Constants.PRICE + "' field");
75+
+ Constants.PRICE + "' field.");
7676
}
7777
}
7878
return target;

NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/RestProviderJersey.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public <REQ, RES> RestResponse<RES> call(final String httpMethod, final String u
101101
restResponse.setEntity(readEntity(response, responseType));
102102
return restResponse;
103103
} catch (final RuntimeException e) {
104-
throw new RestException("Exception while calling service", e);
104+
throw new RestException("Exception while calling service.", e);
105105
}
106106
}
107107

@@ -175,7 +175,7 @@ private <RES> RES readEntity(final Response response, final Class<RES> responseT
175175
}
176176
final String body = buffered ? " '" + response.readEntity(String.class) + "' of type '"
177177
+ response.getMediaType() + "'" : "";
178-
throw new RestException("Could not interpret the response body" + body, ex);
178+
throw new RestException("Could not interpret the response body" + body + ".", ex);
179179
}
180180
}
181181
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToEntityBaseConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public T convert(final Item source) throws ConversionException {
3636
final String entityClass = target.getClass().getInterfaces()[0].getSimpleName();
3737
if (!entityClass.equals(source.getType())) {
3838
final String sourceType = (source.getType() != null) ? source.getType() : "<null>";
39-
throw new ConversionException(String.format("Wrong item type '%s', expected '%s'", sourceType, entityClass));
39+
throw new ConversionException(
40+
String.format("Wrong item type '%s', expected '%s'.", sourceType, entityClass));
4041
}
4142

4243
target.setActive(Boolean.parseBoolean(

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicenseTypePropertiesConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ItemToLicenseTypePropertiesConverter implements Converter<Item, Lic
2727
public LicenseTypeProperties convert(final Item source) throws ConversionException {
2828
if (!Constants.Utility.LICENSE_TYPE.equals(source.getType())) {
2929
final String sourceType = (source.getType() != null) ? source.getType() : "<null>";
30-
throw new ConversionException(String.format("Wrong item type '%s', expected '%s'", sourceType,
30+
throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType,
3131
Constants.Utility.LICENSE_TYPE));
3232
}
3333

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicensingModelPropertiesConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ItemToLicensingModelPropertiesConverter implements Converter<Item,
2727
public LicensingModelProperties convert(final Item source) throws ConversionException {
2828
if (!Constants.Utility.LICENSING_MODEL_PROPERTIES.equals(source.getType())) {
2929
final String sourceType = (source.getType() != null) ? source.getType() : "<null>";
30-
throw new ConversionException(String.format("Wrong item type '%s', expected '%s'", sourceType,
30+
throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType,
3131
Constants.Utility.LICENSING_MODEL_PROPERTIES));
3232
}
3333

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemsToValidationResultConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ValidationResult convert(final Netlicensing source) throws ConversionExce
5656
}
5757

5858
if (productModuleNumber == null) {
59-
throw new ConversionException(String.format("Validation item does not contain property '%s'",
59+
throw new ConversionException(String.format("Validation item does not contain property '%s'.",
6060
Constants.ProductModule.PRODUCT_MODULE_NUMBER));
6161
}
6262

NetLicensingClient/src/main/java/com/labs64/netlicensing/service/NetLicensingService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ public Netlicensing request(final Context context, final String method, final St
212212
case NO_CONTENT:
213213
return null;
214214
default:
215-
throw new RestException(String.format("Unsupported response status code %s: %s",
215+
throw new RestException(String.format("Unsupported response status code %s: %s.",
216216
status.getStatusCode(), status.getReasonPhrase()));
217217
}
218218
} else {
219219
if (SchemaFunction.hasErrorInfos(response.getEntity())) {
220220
throw new ServiceException(status, response.getHeaders(), response.getEntity());
221221
} else {
222-
throw new RestException(String.format("Unknown service error %s: %s", status.getStatusCode(),
222+
throw new RestException(String.format("Unknown service error %s: %s.", status.getStatusCode(),
223223
status.getReasonPhrase()));
224224
}
225225
}
@@ -236,7 +236,7 @@ public Netlicensing request(final Context context, final String method, final St
236236
*/
237237
private void configure(final RestProvider restProvider, final Context context) throws RestException {
238238
if (context.getSecurityMode() == null) {
239-
throw new RestException("Security mode must be specified");
239+
throw new RestException("Security mode must be specified.");
240240
}
241241
switch (context.getSecurityMode()) {
242242
case BASIC_AUTHENTICATION:
@@ -248,7 +248,7 @@ private void configure(final RestProvider restProvider, final Context context) t
248248
case ANONYMOUS_IDENTIFICATION:
249249
break;
250250
default:
251-
throw new RestException("Unknown security mode");
251+
throw new RestException("Unknown security mode.");
252252
}
253253
if (context.containsKey(RestProvider.Configuration.class)) {
254254
final Object config = context.getObject(RestProvider.Configuration.class);

NetLicensingClient/src/main/java/com/labs64/netlicensing/util/JAXBUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ public static <T> T readObjectFromString(final String content, final Class<T> ex
3737

3838
public static <T> T readObjectFromInputStream(final InputStream inputStream, final Class<T> expectedType) {
3939
try {
40-
JAXBContext jaxbContext = JAXBContext.newInstance(expectedType);
41-
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
42-
JAXBElement<T> element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType);
40+
final JAXBContext jaxbContext = JAXBContext.newInstance(expectedType);
41+
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
42+
final JAXBElement<T> element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType);
4343
return element.getValue();
4444
} catch (final JAXBException e) {
45-
throw new RuntimeException("Cannot process resource!", e);
45+
throw new RuntimeException("Cannot process resource.", e);
4646
}
4747
}
4848

4949
public static <T> String xmlEntityToString(final T entity) {
5050
try {
51-
JAXBContext jaxbContext = JAXBContext.newInstance(entity.getClass());
52-
Marshaller marshaller = jaxbContext.createMarshaller();
51+
final JAXBContext jaxbContext = JAXBContext.newInstance(entity.getClass());
52+
final Marshaller marshaller = jaxbContext.createMarshaller();
5353
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
54-
ByteArrayOutputStream out = new ByteArrayOutputStream();
54+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
5555
marshaller.marshal(entity, out);
5656
return out.toString();
5757
} catch (final JAXBException e) {
58-
throw new RuntimeException("Cannot convert object to string !", e);
58+
throw new RuntimeException("Cannot convert object to string.", e);
5959
}
6060
}
6161

0 commit comments

Comments
 (0)