diff --git a/src/main/java/org/springframework/samples/petclinic/domain/model/BaseModel.java b/src/main/java/org/springframework/samples/petclinic/domain/model/BaseModel.java new file mode 100644 index 000000000..7cf979566 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/domain/model/BaseModel.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.domain.model; + +import java.io.Serializable; + +public class BaseModel implements Serializable { + + private Integer id; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public boolean isNew() { + return this.id == null; + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/domain/model/NamedModel.java b/src/main/java/org/springframework/samples/petclinic/domain/model/NamedModel.java new file mode 100644 index 000000000..ea1055e75 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/domain/model/NamedModel.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.domain.model; + +public class NamedModel extends BaseModel { + + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.getName(); + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/domain/model/PersonModel.java b/src/main/java/org/springframework/samples/petclinic/domain/model/PersonModel.java new file mode 100644 index 000000000..b6de99f42 --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/domain/model/PersonModel.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.domain.model; + +public class PersonModel extends BaseModel { + + private String firstName; + + private String lastName; + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + +} diff --git a/src/main/java/org/springframework/samples/petclinic/domain/vet/Specialty.java b/src/main/java/org/springframework/samples/petclinic/domain/vet/Specialty.java new file mode 100644 index 000000000..bfc76e27d --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/domain/vet/Specialty.java @@ -0,0 +1,22 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.domain.vet; + +import org.springframework.samples.petclinic.domain.model.NamedModel; + +public class Specialty extends NamedModel { + +} diff --git a/src/main/java/org/springframework/samples/petclinic/domain/vet/VetEntity.java b/src/main/java/org/springframework/samples/petclinic/domain/vet/VetEntity.java new file mode 100644 index 000000000..dc17253dc --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/domain/vet/VetEntity.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.domain.vet; + +import jakarta.xml.bind.annotation.XmlElement; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.springframework.samples.petclinic.domain.model.PersonModel; +import org.springframework.samples.petclinic.infrastructure.persistence.model.PersonEntity; + +public class VetEntity extends PersonModel { + + private Set specialties; + + protected Set getSpecialtiesInternal() { + if (this.specialties == null) { + this.specialties = new HashSet<>(); + } + return this.specialties; + } + + protected void setSpecialtiesInternal(Set specialties) { + this.specialties = specialties; + } + + @XmlElement + public List getSpecialties() { + return new ArrayList<>(getSpecialtiesInternal()); + } + + public int getNrOfSpecialties() { + return getSpecialtiesInternal().size(); + } + + public void addSpecialty(Specialty specialty) { + getSpecialtiesInternal().add(specialty); + } + +}