All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.osvaldopina.signedcontract.enforcer.jsonhal.HalLinkFindByRelClauseEnforcer Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package com.github.osvaldopina.signedcontract.enforcer.jsonhal;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.osvaldopina.signedcontract.enforcer.BranchClauseEnforcer;
import com.github.osvaldopina.signedcontract.enforcer.Clause;
import com.github.osvaldopina.signedcontract.enforcer.EnforcementError;
import com.github.osvaldopina.signedcontract.enforcer.Navigator;
import com.github.osvaldopina.signedcontract.enforcer.json.navigator.JsonPropertyNavigator;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class HalLinkFindByRelClauseEnforcer extends BranchClauseEnforcer
        implements HalLinksClauseEnforcer {

    private String rel;

    public HalLinkFindByRelClauseEnforcer(String rel, List subClauses) {
        super(subClauses);
        for(HalLinkPropertyClauseEnforcer halLinkPropertyClauseEnforcer:subClauses) {
           if (halLinkPropertyClauseEnforcer instanceof Rel) {
               ((Rel) halLinkPropertyClauseEnforcer).setRel(rel);
           }
        }
        this.rel = rel;
    }


    @Override
    protected Navigator createNavigator() {
        return new JsonPropertyNavigator(rel);
    }

    @Override
    protected List enforceClause(JsonNode documentClause) {
        return Collections.EMPTY_LIST;
    }

    @Override
    protected List verifyNavigation(JsonNode documentClause) {
        if (documentClause == null) {
            return Arrays.asList(new EnforcementError(
                    new StringBuilder()
                            .append("Was expecting to find a hal link with rel [")
                            .append(rel)
                            .append("] but it was not found!")
                            .toString()));
        } else {
            return Collections.EMPTY_LIST;
        }
    }

    public String getRel() {
        return rel;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy