Skip to content

Commit

Permalink
Merge pull request #125 from kbss-cvut/feature/116-update-fault-tree-…
Browse files Browse the repository at this point in the history
…operational-failure-rate

Feature/116 update fault tree operational failure rate
  • Loading branch information
kostobog authored Jun 19, 2024
2 parents e15e780 + 6c76a45 commit 76547ff
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/config/JacksonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import cz.cvut.kbss.jsonld.ConfigParam;
import cz.cvut.kbss.jsonld.jackson.JsonLdModule;
import cz.cvut.kbss.jsonld.jackson.serialization.SerializationConstants;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class JacksonConfig {
Expand All @@ -22,4 +24,10 @@ public ObjectMapper objectMapper() {
return mapper;
}

@Bean(name = "customRestTemplate")
public RestTemplate restTemplate() {
return new RestTemplateBuilder()
// .additionalMessageConverters(new MappingJackson2HttpMessageConverter(objectMapper()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@
public class OperationalDataConfig {

protected Double minOperationalHours;
protected String operationalFailureRateService;

@Autowired
public OperationalDataConfig(Environment env) {
operationalFailureRateService = env.getProperty("operationalFailureRateService");
}
}
94 changes: 92 additions & 2 deletions src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public List<T> findAll(URI contenxt) {
public Optional<T> find(URI id) {
Objects.requireNonNull(id);
try {
EntityDescriptor entityDescriptor = getEntityDescriptor(id);
return Optional.ofNullable(em.find(type, id, entityDescriptor));
return Optional.ofNullable(em.find(type, id));
} catch (RuntimeException e) {
throw new PersistenceException(e);
}
Expand Down Expand Up @@ -211,4 +210,95 @@ public boolean existsWithPredicate(String predicate, String value) {
.getSingleResult();
}

/**
* Add triple in the provided context
* @param subjectURI
* @param property
* @param object
* @param context
*/
public void persistPropertyInContext(URI subjectURI, URI property, Object object, URI context){
Objects.requireNonNull(subjectURI);
Objects.requireNonNull(object);
Objects.requireNonNull(property);
Objects.requireNonNull(subjectURI);

em.createNativeQuery("""
INSERT {
GRAPH ?context{
?subject ?property ?object.
}
}WHERE {}
""")
.setParameter("subject", subjectURI)
.setParameter("property", property)
.setParameter("object", object)
.setParameter("context", context)
.executeUpdate();
}

/**R *
* @param subject
* @param property
* @param object
* @param context
*/
public void addOrReplaceValue(URI subject, URI property, Object object, URI context){
Objects.requireNonNull(subject);
Objects.requireNonNull(object);
Objects.requireNonNull(property);
Objects.requireNonNull(subject);

em.createNativeQuery("""
DELETE{
GRAPH ?context{
?subject ?property ?oldObject.
}
}INSERT {
GRAPH ?context{
?subject ?property ?object.
}
}WHERE {
OPTIONAL{
GRAPH ?context{
?subject ?property ?oldObject.
}
}
}
""")
.setParameter("subject", subject)
.setParameter("property", property)
.setParameter("object", object)
.setParameter("context", context)
.executeUpdate();
}


/**
* Removes all triples with subject subjectURi and property propertyURI in context.
* @param subjectURI
* @param propertyURI
* @param context
*/
public void removeAll(URI subjectURI, URI propertyURI, URI context){
Objects.requireNonNull(subjectURI);
Objects.requireNonNull(propertyURI);
Objects.requireNonNull(subjectURI);

em.createNativeQuery("""
DELETE {
GRAPH ?context{
?subject ?propertyURI ?object.
}
}WHERE {
GRAPH ?context{
?subject ?propertyURI ?object.
}
}
""")
.setParameter("subject", subjectURI)
.setParameter("propertyURI", propertyURI)
.setParameter("context", context)
.executeUpdate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cz.cvut.kbss.analysis.dao;

import cz.cvut.kbss.analysis.config.conf.PersistenceConf;
import cz.cvut.kbss.analysis.model.FailureRateEstimate;
import cz.cvut.kbss.analysis.service.IdentifierService;
import cz.cvut.kbss.analysis.util.Vocabulary;
import cz.cvut.kbss.jopa.model.EntityManager;
import org.springframework.stereotype.Repository;

import java.net.URI;

@Repository
public class FailureRateEstimateDao extends BaseDao<FailureRateEstimate>{
protected final static URI HAS_ESTIMATE_PROP = URI.create(Vocabulary.s_p_has_estimate);
protected final static URI VALUE_PROP = URI.create(Vocabulary.s_p_value);

public FailureRateEstimateDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) {
super(FailureRateEstimate.class, em, config, identifierService);
}

public void setHasEstimate(URI failureRateUri, FailureRateEstimate estimate, URI context) {
addOrReplaceValue(failureRateUri, HAS_ESTIMATE_PROP, estimate.getUri(), context);
}

public void setValue(URI failureRateEstimateUri, Double value, URI context) {
addOrReplaceValue(failureRateEstimateUri, VALUE_PROP, value, context);
}
}
6 changes: 6 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/FaultEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@Repository
public class FaultEventDao extends NamedEntityDao<FaultEvent> {

public static final URI PROBABILITY_PROP = URI.create(Vocabulary.s_p_probability);

@Autowired
protected FaultEventDao(EntityManager em, PersistenceConf config, IdentifierService identifierService) {
super(FaultEvent.class, em, config, identifierService);
Expand Down Expand Up @@ -52,6 +54,10 @@ protected EntityDescriptor getEntityDescriptorInContext(URI graph){
return entityDescriptor;
}

public void setProbability(URI faultEventUri, Double probability, URI context){
addOrReplaceValue(faultEventUri, PROBABILITY_PROP, probability, context);
}

public EntityDescriptor getRectangleDescriptor(URI uri){
URI graph = getContext(uri);
EntityDescriptor entityDescriptor = new EntityDescriptor(graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.stereotype.Repository;

import java.net.URI;
import java.util.Objects;

@Repository
public class OperationalDataFilterDao extends BaseDao<OperationalDataFilter> {
Expand All @@ -35,23 +34,7 @@ public OperationalDataFilter findByEntity(URI entity) {
* @param filter should have non-null uri and context
*/
public void persistHasFilter(URI entityURI, OperationalDataFilter filter){

Objects.requireNonNull(entityURI);
Objects.requireNonNull(filter);
Objects.requireNonNull(filter.getUri());

em.createNativeQuery("""
INSERT {
GRAPH ?context{
?entity ?hasOperationalDataFilter ?filter.
}
}WHERE {}
""")
.setParameter("context", filter.getContext())
.setParameter("entity", entityURI)
.setParameter("hasOperationalDataFilter", HAS_OPERATIONAL_DATA_FILTER_PROP)
.setParameter("filter", filter.getUri())
.executeUpdate();
addOrReplaceValue(entityURI, HAS_OPERATIONAL_DATA_FILTER_PROP, filter, filter.getContext());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cz.cvut.kbss.analysis.model.opdata;

import cz.cvut.kbss.jopa.model.annotations.*;

import java.net.URI;


@OWLClass(iri = "http://item-failure-rate")
public class ItemFailureRate {

@Id
protected URI uri;

@OWLDataProperty(iri = "http://failureRate")
protected Double failureRate;

public URI getUri() {
return uri;
}

public void setUri(URI uri) {
this.uri = uri;
}

public Double getFailureRate() {
return failureRate;
}

public void setFailureRate(Double failureRate) {
this.failureRate = failureRate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,11 @@ protected void validate(T instance) {
}
}

public URI getToolContext(URI uri){
return getToolContext(uri.toString());
}

public URI getToolContext(String uri){
return URI.create(uri + "-jopa");
}
}
Loading

0 comments on commit 76547ff

Please sign in to comment.