Completed scenarios.xml.
Added Customer protection against eating non existing food. Added blocking of logs from Money.class Fixed some stuff and bugs.
This commit is contained in:
parent
f1e66fc4b7
commit
6c11f188ee
@ -53,6 +53,23 @@ pass
|
|||||||
<steps>
|
<steps>
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
doaction STORE_FRUIT hruška
|
||||||
|
doaction WRAP_INTO_GIFT_PACKAGE banán
|
||||||
|
sell VEGETABLE okurka
|
||||||
|
sell FRUIT banán
|
||||||
|
doaction WRAP_INTO_GIFT_PACKAGE jablko
|
||||||
|
sell FRUIT hruška
|
||||||
|
sell FRUIT jablko
|
||||||
|
doaction WRAP_INTO_GIFT_PACKAGE paprika
|
||||||
|
sell VEGETABLE paprika
|
||||||
|
pass
|
||||||
|
sell MEAT vepřové
|
||||||
|
doaction WRAP_INTO_GIFT_PACKAGE kuřecí
|
||||||
|
sell MEAT hovězí
|
||||||
|
sell MEAT kuřecí
|
||||||
</steps>
|
</steps>
|
||||||
</scenario>
|
</scenario>
|
||||||
<scenario type="Distributor">
|
<scenario type="Distributor">
|
||||||
@ -60,6 +77,24 @@ pass
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
sell VEGETABLE okurka
|
||||||
|
sell FRUIT banán
|
||||||
|
pass
|
||||||
|
sell FRUIT hruška
|
||||||
|
sell FRUIT jablko
|
||||||
|
pass
|
||||||
|
sell VEGETABLE paprika
|
||||||
|
pass
|
||||||
|
sell MEAT vepřové
|
||||||
|
pass
|
||||||
|
sell MEAT hovězí
|
||||||
|
sell MEAT kuřecí
|
||||||
</steps>
|
</steps>
|
||||||
</scenario>
|
</scenario>
|
||||||
<scenario type="Customer">
|
<scenario type="Customer">
|
||||||
@ -68,6 +103,25 @@ pass
|
|||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
consume
|
||||||
|
consume
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
consume
|
||||||
|
consume
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
consume
|
||||||
|
consume
|
||||||
|
consume
|
||||||
|
consume
|
||||||
</steps>
|
</steps>
|
||||||
</scenario>
|
</scenario>
|
||||||
</scenarios>
|
</scenarios>
|
||||||
@ -1,6 +1,9 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.node;
|
package cz.cvut.fel.sit.omo.foodchain.node;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customer node
|
* Customer node
|
||||||
@ -15,7 +18,14 @@ public class Customer extends NodeBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void consumeProduct() {
|
public void consumeProduct() {
|
||||||
|
if(getStorage().getNumberOfStoredProducts() == 0)
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.WARNING, this.nodeType + " tried to consume non existing product.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
int i = new Random().nextInt(getStorage().getNumberOfStoredProducts());
|
int i = new Random().nextInt(getStorage().getNumberOfStoredProducts());
|
||||||
|
Product temp = getStorage().getProducts().get(i);
|
||||||
getStorage().getProducts().remove(i);
|
getStorage().getProducts().remove(i);
|
||||||
|
LOGGER.log(Level.INFO, this.nodeType + " consumed " + temp.getName() + " " + temp.getProductType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class Storage
|
|||||||
*/
|
*/
|
||||||
public Product getProduct(String name, ProductType type)
|
public Product getProduct(String name, ProductType type)
|
||||||
{
|
{
|
||||||
return products.stream().filter(ch -> ch.getProductType() == type && ch.getName().equals(name)).findFirst().orElse(null);
|
return products.stream().filter(ch -> (ch.getProductType().equals(type) || type.equals(ProductType.ALL)) && ch.getName().equals(name)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Product> getProducts()
|
public List<Product> getProducts()
|
||||||
|
|||||||
@ -50,7 +50,8 @@ public class ProductTransaction extends Transaction {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "ProductTransaction{" +
|
return "ProductTransaction{" +
|
||||||
"product=" + product.getName() +
|
"product=" + product.getName() +
|
||||||
'}';
|
", creator="+this.getNodeCreator().getNodeType() +
|
||||||
|
", receiver="+this.getNodeReceiver().getNodeType() + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -14,6 +14,7 @@ public class FoodChainReportVisitor implements ReportTextVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append("-----PRODUCT-----").append(ln)
|
builder.append("-----PRODUCT-----").append(ln)
|
||||||
.append("Name: ").append(product.getName()).append(ln)
|
.append("Name: ").append(product.getName()).append(ln)
|
||||||
.append("Type: ").append(product.getProductType()).append(ln)
|
.append("Type: ").append(product.getProductType()).append(ln)
|
||||||
|
|||||||
@ -7,10 +7,7 @@ import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
|||||||
|
|
||||||
public class SecurityReportVisitor implements ReportTextVisitor {
|
public class SecurityReportVisitor implements ReportTextVisitor {
|
||||||
@Override
|
@Override
|
||||||
public String visit(NodeBase node) {
|
public String visit(NodeBase node) { return null; }
|
||||||
return
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(Product product) {
|
public String visit(Product product) {
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.util;
|
package cz.cvut.fel.sit.omo.foodchain.util;
|
||||||
|
|
||||||
|
import org.javamoney.moneta.Money;
|
||||||
|
import org.javamoney.moneta.format.CurrencyStyle;
|
||||||
|
|
||||||
|
import javax.money.format.AmountFormatQueryBuilder;
|
||||||
|
import javax.money.format.MonetaryAmountFormat;
|
||||||
|
import javax.money.format.MonetaryFormats;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
@ -18,15 +25,16 @@ public class ReportLogger extends Handler
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append(record.getMessage());
|
sb.append(record.getMessage());
|
||||||
|
|
||||||
|
// Blocking Money logs because spams "Using default formatter toString()." after printing MonetaryAmount in reports
|
||||||
|
if(record.getSourceClassName().equals(Money.class.getName()))return;
|
||||||
|
|
||||||
if(record.getLevel().equals(Level.WARNING) || record.getLevel().equals(Level.SEVERE))
|
if(record.getLevel().equals(Level.WARNING) || record.getLevel().equals(Level.SEVERE))
|
||||||
{
|
{
|
||||||
System.err.println(sb.toString());
|
System.err.println(sb.toString());
|
||||||
//todo add some outprint to report log
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
//todo add some outprint to report log
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package cz.cvut.fel.sit.omo.foodchain.util;
|
|||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
import cz.cvut.fel.sit.omo.foodchain.FoodChain;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
import cz.cvut.fel.sit.omo.foodchain.channel.ChannelBase;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.node.NodeBase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
|
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
|
||||||
@ -28,7 +29,7 @@ public class Ticker {
|
|||||||
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
PoolDatabase db = FoodChain.getFactoryManager().getPoolDatabaseInstance();
|
||||||
boolean productBool = db.getProductPoolInstance().findAll().stream().filter(Product::tick).count() == 0; // change duration of action
|
boolean productBool = db.getProductPoolInstance().findAll().stream().filter(Product::tick).count() == 0; // change duration of action
|
||||||
boolean channelBool = db.getChannelPoolInstance().findAll().stream().filter(ChannelBase::tick).count() == 0; // change TTL of requirements
|
boolean channelBool = db.getChannelPoolInstance().findAll().stream().filter(ChannelBase::tick).count() == 0; // change TTL of requirements
|
||||||
db.getNodePoolInstance().findAll().forEach(n -> n.tick()); // receive transactions
|
db.getNodePoolInstance().findAll().forEach(NodeBase::tick); // receive transactions
|
||||||
boolean scenarioBool = db.getScenarioPoolInstance().findAll().stream().filter(Scenario::tick).count() == 0; // do next step in scenario
|
boolean scenarioBool = db.getScenarioPoolInstance().findAll().stream().filter(Scenario::tick).count() == 0; // do next step in scenario
|
||||||
if (channelBool && productBool && scenarioBool) stop();
|
if (channelBool && productBool && scenarioBool) stop();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user