Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

refactor #40

Merged
merged 8 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

target
.idea
10 changes: 4 additions & 6 deletions src/main/java/io/github/eocqrs/cmig/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@

package io.github.eocqrs.cmig;

import io.github.eocqrs.cmig.sha.StateChanges;
import org.cactoos.Scalar;
/*
* @todo #32:30m/DEV design State interface
*/

/**
* State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public interface State extends Scalar<String> {

public interface State extends Scalar<StateChanges> {
l3r8yJ marked this conversation as resolved.
Show resolved Hide resolved
@Override
String value() throws Exception;
StateChanges value();

}
6 changes: 3 additions & 3 deletions src/main/java/io/github/eocqrs/cmig/meta/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.io.ResourceOf;

/**
Expand All @@ -33,7 +33,7 @@
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public final class Author implements Scalar<String> {
public final class Author implements Text {

/**
* XML.
Expand Down Expand Up @@ -75,7 +75,7 @@ public Author(final String name, final String id)
}

@Override
public String value() throws Exception {
public String asString() {
return this.xml.xpath(
"/states/changeState[@id='%s']/@author"
.formatted(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/meta/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Names(final String name, final String id)
}

@Override
public List<String> value() throws Exception {
public List<String> value() {
return this.xml.xpath(
"/states/changeState[@id='%s']/files/file/@path"
.formatted(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/meta/XpathList.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
public interface XpathList extends Scalar<List<String>> {

@Override
List<String> value() throws Exception;
List<String> value();
}
2 changes: 1 addition & 1 deletion src/main/java/io/github/eocqrs/cmig/session/Cassandra.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public interface Cassandra extends Scalar<Session>, Closeable {

@Override
Session value() throws Exception;
Session value();

@Override
void close() throws IOException;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/github/eocqrs/cmig/session/Cql.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public interface Cql {
/**
* Apply Query.
*
* @throws Exception if something went wrong.
*/
void apply() throws Exception;
void apply();
}
4 changes: 2 additions & 2 deletions src/main/java/io/github/eocqrs/cmig/session/InFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
}

@Override
public void apply() throws Exception {
public void apply() {
this.cassandra.value()
.execute(
new TextOf(
new ResourceOf(this.name)
).asString()
).toString()

Check warning on line 65 in src/main/java/io/github/eocqrs/cmig/session/InFile.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/cmig/session/InFile.java#L65

Added line #L65 was not covered by tests
);
}
}
6 changes: 2 additions & 4 deletions src/main/java/io/github/eocqrs/cmig/session/Simple.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

import java.io.IOException;

/**
* Simple Cassandra.
*
Expand Down Expand Up @@ -68,12 +66,12 @@ public Simple(
}

@Override
public Session value() throws Exception {
public Session value() {
return this.cluster.connect();
}

@Override
public void close() throws IOException {
public void close() {
this.cluster.close();
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/github/eocqrs/cmig/sha/Sha.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public final class Sha implements Text {
* State ID.
*/
private final String id;

/**
* Master file.
*/
private final String master;

/**
* CMIG directory.
*/
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/io/github/eocqrs/cmig/sha/StateChanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.github.eocqrs.cmig.meta.XpathList;
import org.cactoos.Scalar;
import org.cactoos.io.ResourceOf;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;

import java.util.List;
Expand All @@ -42,6 +41,7 @@ public final class StateChanges implements Scalar<List<String>> {
* XPATH lists.
*/
private final XpathList list;

/**
* CMIG directory.
*/
Expand All @@ -60,21 +60,17 @@ public StateChanges(final XpathList lst, final String cmg) {

@Override
public List<String> value() throws Exception {
final List<String> contents = new ListOf<>();
final List<String> files = this.list.value();
for (final String file : files) {
final String content =
new TextOf(
return this.list.value()
.stream()
.map(
file -> new TextOf(
new ResourceOf(
"%s/%s"
.formatted(
this.cmig,
file
)
"%s/%s".formatted(
this.cmig,
file
)
)
).asString();
contents.add(content);
}
return contents;
).toString()
).toList();
}
}
2 changes: 1 addition & 1 deletion src/test/java/io/github/eocqrs/cmig/meta/AuthorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void readsAuthorInfoInRightFormat() throws Exception {
new Author(
"cmig/master.xml",
"1"
).value(),
).asString(),
new IsEqual<>(
"test"
)
Expand Down