Skip to content

Commit

Permalink
KAA-1279: Fixed about 50 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sashadidukh committed Sep 29, 2016
1 parent f773096 commit 7ad3702
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 80 deletions.
Expand Up @@ -45,7 +45,7 @@ private AvroUtils() {
*
* @return list of generated bytes.
*/
public static byte[] generateUUIDBytes() {
public static byte[] generateUuidBytes() {
UUID uuid = UUID.randomUUID();

ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[UUID_SIZE]);
Expand All @@ -57,7 +57,7 @@ public static byte[] generateUUIDBytes() {

public static GenericData.Fixed generateUuidObject() {
Schema avroSchema = Schema.createFixed(UUID_TYPE, null, KAA_NAMESPACE, UUID_SIZE);
return new GenericData.Fixed(avroSchema, generateUUIDBytes());
return new GenericData.Fixed(avroSchema, generateUuidBytes());
}

public static Schema getSchemaByType(Schema schema, Schema.Type type) {
Expand Down Expand Up @@ -122,7 +122,8 @@ private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) {
.filter(f -> !f.name().equals(UUID_FIELD))
.forEach(f -> injectUuidsFromJsonNodes(json.get(f.name()), f.schema()));

boolean addressable = schema.getFields().stream().filter(f -> f.name().equals(UUID_FIELD)).findFirst().isPresent();
boolean addressable = schema.getFields().stream().filter(f -> f.name().equals(
UUID_FIELD)).findFirst().isPresent();
if (addressable) {
((ObjectNode) json).put(UUID_FIELD, (Integer) null);
}
Expand All @@ -132,7 +133,7 @@ private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) {
.forEach(s -> injectUuidsFromJsonNodes(json.get(s.getName()), s));
break;
case ARRAY:
json.getElements().forEachRemaining((e) -> injectUuids(e, schema.getElementType()));
json.getElements().forEachRemaining((elem) -> injectUuids(elem, schema.getElementType()));
break;
default:
return json;
Expand All @@ -151,8 +152,9 @@ public static void removeUuids(JsonNode json) {
}

for (JsonNode node : json) {
if (node.isContainerNode())
if (node.isContainerNode()) {
removeUuids(node);
}
}
}
}
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;

/**
* Simple container for resync delta encoded using base schema
* Simple container for resync delta encoded using base schema.
*
* @author Andrew Shvayka
*/
Expand Down
Expand Up @@ -27,10 +27,12 @@
public class DefaultDeltaCalculatorFactory implements DeltaCalculatorFactory {

/* (non-Javadoc)
* @see org.kaaproject.kaa.server.operations.service.delta.DeltaCalculatorFactory#createDeltaCalculator(java.lang.String)
* @see org.kaaproject.kaa.server.operations.service.delta.DeltaCalculatorFactory
* #createDeltaCalculator(java.lang.String)
*/
@Override
public DeltaCalculationAlgorithm createDeltaCalculator(ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema) {
public DeltaCalculationAlgorithm createDeltaCalculator(
ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema) {
Schema protocolSchema = new Schema.Parser().parse(protocolSchemaBody.getRawSchema());
Schema baseSchema = new Schema.Parser().parse(baseDataSchema.getRawSchema());
return new DefaultDeltaCalculationAlgorithm(protocolSchema, baseSchema);
Expand Down
Expand Up @@ -30,7 +30,7 @@ public interface DeltaCalculationAlgorithm {
/**
* Calculates delta merging new and old configurations.
*
* @param oldConfiguration old configuration data (binary)
* @param endpointConfiguration old configuration data (binary)
* @param newConfigurationBody the new configuration body (binary)
* @return the raw binary delta
* @throws IOException Signals that an I/O exception has occurred.
Expand All @@ -47,5 +47,6 @@ RawBinaryDelta calculate(BaseData endpointConfiguration, BaseData newConfigurati
* @throws IOException Signals that an I/O exception has occurred.
* @throws DeltaCalculatorException the delta calculator exception
*/
RawBinaryDelta calculate(BaseData newConfigurationBody) throws IOException, DeltaCalculatorException;
RawBinaryDelta calculate(BaseData newConfigurationBody)
throws IOException, DeltaCalculatorException;
}
Expand Up @@ -32,6 +32,7 @@ public interface DeltaCalculatorFactory {
* @param baseDataSchema base the schema body
* @return the delta calculator
*/
DeltaCalculationAlgorithm createDeltaCalculator(ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema);
DeltaCalculationAlgorithm createDeltaCalculator(
ProtocolSchema protocolSchemaBody, BaseSchema baseDataSchema);

}
Expand Up @@ -46,7 +46,6 @@ public ConfigurationGenerationException(String message) {

/**
* Constructs a new configuration processing exception.
* <p>
* Note that the detail message associated with {@code cause} is <i>not</i>
* automatically incorporated in this exception's detail message.
*
Expand Down
Expand Up @@ -52,5 +52,6 @@ public interface DefaultRecordGenerationAlgorithm<T extends KaaData> {
* @return the configuration by name
* @throws ConfigurationGenerationException the configuration processing exception
*/
GenericRecord getConfigurationByName(String name, String namespace) throws ConfigurationGenerationException;
GenericRecord getConfigurationByName(String name, String namespace)
throws ConfigurationGenerationException;
}
Expand Up @@ -43,14 +43,17 @@

/**
* Default implementation of
* {@link org.kaaproject.kaa.server.common.dao.configuration.DefaultRecordGenerationAlgorithm}
* {@link
* org.kaaproject.kaa.server.common.core.algorithms.generation.DefaultRecordGenerationAlgorithm}
*/
public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends KaaData<U>> implements DefaultRecordGenerationAlgorithm<T> {
public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends KaaData<U>>
implements DefaultRecordGenerationAlgorithm<T> {

/**
* The Constant LOG.
*/
private static final Logger LOG = LoggerFactory.getLogger(DefaultRecordGenerationAlgorithmImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(
DefaultRecordGenerationAlgorithmImpl.class);

/**
* The processed types.
Expand Down Expand Up @@ -83,8 +86,10 @@ public class DefaultRecordGenerationAlgorithmImpl<U extends KaaSchema, T extends
* @param kaaSchema the base schema
* @throws ConfigurationGenerationException the configuration processing exception
*/
public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> factory) throws ConfigurationGenerationException {
LOG.debug("Generating default configuration for configuration schema: " + kaaSchema.getRawSchema());
public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> factory)
throws ConfigurationGenerationException {
LOG.debug("Generating default configuration for configuration schema: "
+ kaaSchema.getRawSchema());

this.rootSchema = kaaSchema;
this.dataFactory = factory;
Expand All @@ -101,7 +106,8 @@ public DefaultRecordGenerationAlgorithmImpl(U kaaSchema, KaaDataFactory<U, T> fa
* @return generated value.
* @throws ConfigurationGenerationException the configuration processing exception.
*/
private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws ConfigurationGenerationException {
private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault)
throws ConfigurationGenerationException {
if (byDefault.isArray() && AvroUtils.getSchemaByType(schemaNode, Type.BYTES) != null) {
// if this is a 'bytes' type then convert json bytes array to
// avro 'bytes' representation or
Expand Down Expand Up @@ -142,7 +148,8 @@ private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws C
return byDefault.asText();
}
}
throw new ConfigurationGenerationException("Default value " + byDefault.toString() + " is not applicable for the field");
throw new ConfigurationGenerationException("Default value " + byDefault.toString()
+ " is not applicable for the field");
}

/**
Expand All @@ -153,7 +160,8 @@ private Object applyDefaultValue(Schema schemaNode, JsonNode byDefault) throws C
* @return generated value for input type.
* @throws ConfigurationGenerationException configuration processing exception
*/
private Object processType(Schema schemaNode, JsonNode byDefault) throws ConfigurationGenerationException {
private Object processType(Schema schemaNode, JsonNode byDefault)
throws ConfigurationGenerationException {
if (byDefault != null && !byDefault.isNull()) {
return applyDefaultValue(schemaNode, byDefault);
}
Expand Down Expand Up @@ -239,7 +247,8 @@ private Object processArray() {
* @return generated value for input enum type.
*/
private Object processEnum(Schema schemaNode) {
GenericEnumSymbol result = new GenericData.EnumSymbol(schemaNode, schemaNode.getEnumSymbols().get(0));
GenericEnumSymbol result = new GenericData.EnumSymbol(schemaNode,
schemaNode.getEnumSymbols().get(0));
return result;
}

Expand Down Expand Up @@ -279,32 +288,31 @@ private Object processField(Field fieldDefinition) throws ConfigurationGeneratio
}

/* (non-Javadoc)
* @see org.kaaproject.kaa.server.common.dao.configuration.ConfigurationProcessor#getRootConfiguration()
*/
@Override
public final GenericRecord getRootConfiguration() throws ConfigurationGenerationException {
return getConfigurationByName(avroBaseSchema.getName(), avroBaseSchema.getNamespace());
}

/* (non-Javadoc)
* @see org.kaaproject.kaa.server.common.dao.configuration.ConfigurationProcessor#getRootJsonConfiguration()
*/
@Override
public final T getRootData() throws IOException, ConfigurationGenerationException {
GenericRecord root = getRootConfiguration();
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(root.getSchema());
try {
return dataFactory.createData(rootSchema, converter.encodeToJson(root));
} catch (RuntimeException e) {
} catch (RuntimeException ex) {
// NPE is thrown if "null" was written into a field that is not nullable
// CGE is thrown if value of wrong type was written into a field
LOG.error("Unexpected exception occurred while generating configuration.", e);
throw new ConfigurationGenerationException(e);
LOG.error("Unexpected exception occurred while generating configuration.", ex);
throw new ConfigurationGenerationException(ex);
}
}

@Override
public final GenericRecord getConfigurationByName(String name, String namespace) throws ConfigurationGenerationException {
public final GenericRecord getConfigurationByName(String name, String namespace)
throws ConfigurationGenerationException {
if (name == null || namespace == null) {
return null;
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public class ArrayOverrideStrategyResolver {
/**
* Instantiates a new array merge strategy resolver.
*
* @param configurationSchema the configuration schema
* @param types the configuration schema types
* @throws IOException Signals that an I/O exception has occurred.
*/
public ArrayOverrideStrategyResolver(Map<String, Schema> types) throws IOException {
Expand All @@ -52,15 +52,18 @@ public ArrayOverrideStrategyResolver(Map<String, Schema> types) throws IOExcepti
/**
* Resolve.
*
* @param parent the parent
* @param childName the child name
* @param name the parent name
* @param namespace the namespace
* @param childName the child name
* @return the array merge strategy
* @throws OverrideException the merge exception
*/
public ArrayOverrideStrategy resolve(String name, String namespace, String childName) throws OverrideException {
public ArrayOverrideStrategy resolve(String name, String namespace, String childName)
throws OverrideException {
Schema schemaForParent = schemaTypes.get(namespace + "." + name);
if (schemaForParent == null) {
throw new OverrideException(MessageFormat.format("Failed to find Schema with Name ''{0}'' and namespace ''{1}''", name, namespace));
throw new OverrideException(MessageFormat.format(
"Failed to find Schema with Name ''{0}'' and namespace ''{1}''", name, namespace));
}
String mergeStrategyName = findMergeStrategy(schemaForParent, childName);

Expand Down

0 comments on commit 7ad3702

Please sign in to comment.