CropTraitTranslationService.java

/*
 * Copyright 2020 Global Crop Diversity Trust
 *
 * 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
 *
 *   http://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.gringlobal.service;

import java.io.Serializable;
import java.util.List;

import org.gringlobal.model.CropTrait;
import org.gringlobal.model.CropTraitAttach;
import org.gringlobal.model.CropTraitLang;
import org.gringlobal.service.CropTraitCodeTranslationService.TranslatedCropTraitCode;
import org.gringlobal.service.filter.CropTraitFilter;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * @author Maxym Borodenko
 */
public interface CropTraitTranslationService extends TranslationService<CropTrait, CropTraitLang, CropTraitTranslationService.TranslatedCropTrait, CropTraitFilter> {

	public static class TranslatedCropTrait extends TranslationService.Translation<CropTrait, CropTraitLang> implements Serializable {
		private static final long serialVersionUID = -499661865275678776L;

		@JsonInclude(JsonInclude.Include.NON_EMPTY)
		@JsonProperty(access = JsonProperty.Access.READ_ONLY)
		public List<TranslatedCropTraitCode> codes;
		@JsonProperty(access = JsonProperty.Access.READ_ONLY)
		public List<CropTraitAttach> attachments;

		public static TranslatedCropTrait from(CropTrait cropTrait, String title, String description, List<TranslatedCropTraitCode> codes) {
			TranslatedCropTrait translatedCropTrait = new TranslatedCropTrait();
			translatedCropTrait.entity = cropTrait;
			translatedCropTrait.title = title;
			translatedCropTrait.description = description;
			translatedCropTrait.codes = codes;
			return translatedCropTrait;
		}
	}

}