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

states instead of files #34

Merged
merged 5 commits into from
Aug 11, 2023
Merged
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
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 (abialiauski.dev@gmail.com)
* @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 (abialiauski.dev@gmail.com)
* @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;
}
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.
* Author of State.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
public final class Authors implements XpathList {
public final class Author 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 Author(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 Author(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 (abialiauski.dev@gmail.com)
* @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
)
);
}
}
87 changes: 87 additions & 0 deletions src/main/java/io/github/eocqrs/cmig/sha/Sha.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.Names;
import org.cactoos.Text;
import org.cactoos.bytes.Sha256DigestOf;
import org.cactoos.io.InputOf;
import org.cactoos.text.HexOf;

import java.util.List;

/**
* SHA256 for State.
*
* @author Aliaksei Bialiauski (0.0.0)
* @since 0.0.0
*/
public final class Sha implements Text {

/**
* State ID.
*/
private final String id;
/**
* Master file.
*/
private final String master;
/**
* CMIG directory.
*/
private final String cmig;

/**
* Ctor.
* @param id State ID
* @param mst Master file
* @param cmg CMIG directory
*/
public Sha(
final String id,
final String mst,
final String cmg
) {
this.id = id;
this.master = mst;
this.cmig = cmg;
}

@Override
public String asString() throws Exception {
final List<String> contents = new StateChanges(
new Names(
this.master,
this.id
),
this.cmig
).value();
return new HexOf(
new Sha256DigestOf(
new InputOf(
contents.toString()
)
)
).asString();
}
}
Loading