Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generic edit from console #175

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private Builder(Repository repo) {
@Setter
private boolean replica = false;

@SuppressWarnings("unchecked")
public <T> AttributeDescriptorImpl<T> build() {
Objects.requireNonNull(name, "Please specify name");
Objects.requireNonNull(entity, "Please specify entity");
Expand All @@ -66,8 +65,7 @@ public <T> AttributeDescriptorImpl<T> build() {
return new AttributeDescriptorImpl<>(
name, entity,
schemeUri,
factory.map(f -> (ValueSerializer<T>)f.getValueSerializer(schemeUri))
.orElse(null),
factory.map(f -> f.<T>getValueSerializer(schemeUri)).orElse(null),
replica);
}
}
Expand Down
12 changes: 11 additions & 1 deletion core/src/main/java/cz/o2/proxima/util/Optionals.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@

import java.util.Optional;

/**
* Utility class for manipulation with {@link Optional}
*/
public class Optionals {

/**
* Get value from Optional or throw IllegalArgumentException
*
* @param optional Optional object
* @param <T> Generic type Optional
* @return T value from Optional
* @throws IllegalArgumentException in case of empty value
*/
public static <T> T get(Optional<T> optional) {
return optional.orElseThrow(() ->
new IllegalArgumentException("Provided optional is empty."));
Expand Down
39 changes: 39 additions & 0 deletions core/src/test/java/cz/o2/proxima/util/OptionalsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2017-2019 O2 Czech Republic, a.s.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cz.o2.proxima.util;

import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertEquals;

/**
* Tests for utility class {@link Optionals}
*/
public class OptionalsTest {

@Test
public void testGet() {
String foo = "bar";
assertEquals(foo, Optionals.get(Optional.of(foo)));
}

@Test(expected = IllegalArgumentException.class)
public void testGetFromEmpty() {
Optionals.get(Optional.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class IngestServiceTest {
CountDownLatch latch;

@Before
public void setup() throws InterruptedException {
public void setup() {
server = new IngestServer(ConfigFactory.load()
.withFallback(ConfigFactory.load("test-reference.conf"))
.resolve());
Expand All @@ -63,9 +63,7 @@ public void setup() throws InterruptedException {

@Override
public void onNext(Rpc.StatusBulk status) {
for (Rpc.Status s : status.getStatusList()) {
responses.add(s);
}
responses.addAll(status.getStatusList());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion example/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</executions>
<configuration>
<mainClass>cz.o2.proxima.tools.groovy.Compiler</mainClass>
<commandlineArgs>-o ${project.basedir}/target/generated-sources/groovy/cz/o2/proxima/example/Environment.groovy ${project.basedir}/model/src/main/resources/reference.conf</commandlineArgs>
<commandlineArgs>-o ${project.build.directory}/generated-sources/groovy/cz/o2/proxima/example/Environment.groovy ${project.parent.basedir}/model/src/main/resources/reference.conf</commandlineArgs>
</configuration>
</plugin>

Expand Down
16 changes: 16 additions & 0 deletions tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@
<scope>test</scope>
</dependency>


<dependency>
<groupId>cz.o2.proxima</groupId>
<artifactId>proxima-scheme-proto</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cz.o2.proxima</groupId>
<artifactId>proxima-scheme-proto</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Expand Down
18 changes: 16 additions & 2 deletions tools/src/main/java/cz/o2/proxima/tools/groovy/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
Expand All @@ -36,6 +38,7 @@
/**
* A compiler of conf files to groovy object.
*/
@Slf4j
public class Compiler {

private final Configuration conf = new Configuration(Configuration.VERSION_2_3_23);
Expand All @@ -56,7 +59,11 @@ private Compiler(String[] args) throws ParseException {
if (!parsed.hasOption("o")) {
throw new IllegalStateException("Missing config option 'o' for output");
}
output = parsed.getOptionValue("o");
output = parsed.getOptionValue("o").trim();
if (output.length() == 0) {
throw new IllegalArgumentException("Empty option 'o' value for output.");
}
log.debug("Configured output file: {}", output);
configs = parsed.getArgList();

conf.setDefaultEncoding(StandardCharsets.UTF_8.name());
Expand All @@ -67,7 +74,14 @@ private Compiler(String[] args) throws ParseException {

public void run() throws Exception {
Config config = configs.stream()
.map(f -> ConfigFactory.parseFile(new File(f)))
.map(f -> {
File c = new File(f);
if (!c.exists()) {
throw new IllegalArgumentException(
"Unable to find config file " + f + ". Check your configuration.");
}
return ConfigFactory.parseFile(c);
})
.reduce(
ConfigFactory.empty(),
(l, r) -> l.withFallback(r))
Expand Down
Loading