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

Commit

Permalink
#32 sha draft
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Aug 11, 2023
1 parent 2dab3be commit 550a34b
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 86 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ Maven:
In your resources directory you should create a `cmig` directory,
and inside it new XML file, for instance `master.xml`:
```xml
<files>
<file id="1" author="h1alexbel">001-initial.cql</file>
<file id="2" author="somebodyelse">002-clicks-keyspace.cql</file>
</files>
<states>
<changeState id="1" author="h1alexbel">
<files>
<file path="001-initial-keyspace.cql"/>
<file path="002-queries-table.cql"/>
</files>
</changeState>
<changeState id="2" author="h1alexbel">
<files>
<file path="003-stuff.cql"/>
</files>
</changeState>
</states>
```

**Inside all the files you must have only one operation**.
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/github/eocqrs/cmig/Master.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
import io.github.eocqrs.cmig.session.InFile;
import org.cactoos.Scalar;
import org.cactoos.io.ResourceOf;
/*
* @todo #32:45m/DEV Master is set of states inside XML document.
*/


/**
* Master files.
* Set of States.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
Expand All @@ -53,7 +57,10 @@ public final class Master implements Scalar<String> {
* @param doc XML
* @param cs Cassandra
*/
public Master(final XML doc, final Cassandra cs) {
public Master(
final XML doc,
final Cassandra cs
) {
this.xml = doc;
this.cassandra = cs;
}
Expand Down Expand Up @@ -82,7 +89,7 @@ public Master(

@Override
public String value() throws Exception {
new Names(this.xml).value()
new Names(this.xml, "").value()
.forEach(file -> {
try {
new InFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,21 @@
* SOFTWARE.
*/

package io.github.eocqrs.cmig.meta;
package io.github.eocqrs.cmig;

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

import java.util.List;
import org.cactoos.Scalar;
/*
* @todo #32:30m/DEV design State interface
*/

/**
* File IDs.
* State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public final class Ids implements XpathList {

/**
* XML.
*/
private final XML xml;

/**
* Ctor.
*
* @param doc XML
*/
public Ids(final XML doc) {
this.xml = doc;
}

/**
* Ctor.
*
* @param name File name
* @throws Exception if something went wrong
*/
public Ids(final String name) throws Exception {
this(
new XMLDocument(
new ResourceOf(
name
).stream()
)
);
}
public interface State extends Scalar<String> {

@Override
public List<String> value() throws Exception {
return this.xml.xpath("/files/file/@id");
}
String value() throws Exception;
}
31 changes: 22 additions & 9 deletions src/main/java/io/github/eocqrs/cmig/meta/Authors.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,63 @@

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

import java.util.List;

/**
* File authors.
* Authors of State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public final class Authors implements XpathList {
public final class Authors implements Scalar<String> {

/**
* XML.
*/
private final XML xml;
/**
* State ID.
*/
private final String id;

/**
* Ctor.
*
* @param doc XML
* @param id State ID
*/
public Authors(final XML doc) {
public Authors(final XML doc, final String id) {
this.xml = doc;
this.id = id;
}

/**
* Ctor.
*
* @param name File name
* @param id State ID
* @throws Exception if something went wrong
*/
public Authors(final String name) throws Exception {
public Authors(final String name, final String id)
throws Exception {
this(
new XMLDocument(
new ResourceOf(
name
).stream()
)
),
id
);
}

@Override
public List<String> value() throws Exception {
return this.xml.xpath("/files/file/@author");
public String value() throws Exception {
return this.xml.xpath(
"/states/changeState[@id='%s']/@author"
.formatted(
this.id
)
).get(0);
}
}
24 changes: 19 additions & 5 deletions src/main/java/io/github/eocqrs/cmig/meta/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.List;

/**
* File names.
* File names of State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
Expand All @@ -40,34 +40,48 @@ public final class Names implements XpathList {
* XML.
*/
private final XML xml;
/**
* State ID.
*/
private final String id;

/**
* Ctor.
*
* @param doc XML
* @param id State ID
*/
public Names(final XML doc) {
public Names(final XML doc, final String id) {
this.xml = doc;
this.id = id;
}

/**
* Ctor.
*
* @param name File name
* @param id State ID
* @throws Exception if something went wrong
*/
public Names(final String name) throws Exception {
public Names(final String name, final String id)
throws Exception {
this(
new XMLDocument(
new ResourceOf(
name
).stream()
)
),
id
);
}

@Override
public List<String> value() throws Exception {
return this.xml.xpath("/files/file/text()");
return this.xml.xpath(
"/states/changeState[@id='%s']/files/file/@path"
.formatted(
this.id
)
);
}
}
80 changes: 80 additions & 0 deletions src/main/java/io/github/eocqrs/cmig/sha/Contents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.cmig.sha;

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;

/**
* Contents in State.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
public final class Contents implements Scalar<List<String>> {

/**
* XPATH lists.
*/
private final XpathList list;
/**
* CMIG directory.
*/
private final String cmig;

/**
* Ctor.
*
* @param lst XPATH list
* @param cmg CMIG directory
*/
public Contents(final XpathList lst, final String cmg) {
this.list = lst;
this.cmig = 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(
new ResourceOf(
"%s/%s"
.formatted(
this.cmig,
file
)
)
).asString();
contents.add(content);
}
return contents;
}
}
Loading

0 comments on commit 550a34b

Please sign in to comment.