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

io.axway.iron.sample.command.CreatePerson Maven / Gradle / Ivy

package io.axway.iron.sample.command;

import java.util.*;
import javax.annotation.*;
import io.axway.iron.Command;
import io.axway.iron.ReadWriteTransaction;
import io.axway.iron.sample.model.Company;
import io.axway.iron.sample.model.Person;

public interface CreatePerson extends Command {

    String id();

    String name();

    @Nullable
    Date birthDate();

    Collection previousCompanyNames();

    @Override
    default Void execute(ReadWriteTransaction tx) {
        Collection previousCompanyNames = previousCompanyNames();
        if (previousCompanyNames == null) { //TODO command proxy should not return null Collection
            previousCompanyNames = Collections.emptyList();
        }
        Collection previousCompanies = tx.select(Company.class).where(Company::name).allContainedIn(previousCompanyNames);

        tx.insert(Person.class) //
                .set(Person::name).to(name()) //
                .set(Person::id).to(id()) //
                .set(Person::birthDate).to(birthDate()) //
                .set(Person::previousCompanies).to(previousCompanies) //
                .done();

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy