/*
 * Copyright 2014 Space Dynamics Laboratory - Utah State University Research Foundation.
 *
 * 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 edu.usu.sdl.openstorefront.core.entity;

import edu.usu.sdl.openstorefront.common.util.OpenStorefrontConstant;
import edu.usu.sdl.openstorefront.core.annotation.APIDescription;
import edu.usu.sdl.openstorefront.core.annotation.ConsumeField;
import edu.usu.sdl.openstorefront.core.annotation.FK;
import edu.usu.sdl.openstorefront.core.annotation.PK;
import edu.usu.sdl.openstorefront.core.annotation.ValidValueType;
import edu.usu.sdl.openstorefront.validation.HTMLSanitizer;
import edu.usu.sdl.openstorefront.validation.Sanitize;
import edu.usu.sdl.openstorefront.validation.TextSanitizer;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author dshurtleff
 */
@APIDescription("Hold a highlight for the homepage")
public class Highlight
		extends StandardEntity
{

	@PK(generated = true)
	@NotNull
	private String highlightId;

	@NotNull
	@ConsumeField
	@ValidValueType(value = {Highlight.TYPE_ARTICLE, Highlight.TYPE_COMPONENT, Highlight.TYPE_EXTERNAL_LINK}, lookupClass = HighlightType.class)
	@FK(HighlightType.class)
	private String highlightType;

	@NotNull
	@ConsumeField
	@Size(min = 1, max = OpenStorefrontConstant.FIELD_SIZE_GENERAL_TEXT)
	@Sanitize(TextSanitizer.class)
	private String title;

	@NotNull
	@ConsumeField
	@Size(min = 1, max = OpenStorefrontConstant.FIELD_SIZE_DETAILED_DESCRIPTION)
	@Sanitize(HTMLSanitizer.class)
	private String description;

	@ConsumeField
	@Size(min = 0, max = OpenStorefrontConstant.FIELD_SIZE_URL)
	@APIDescription("External URL link")
	private String link;

	public static final String FIELD_TITLE = "title";
	public static final String TYPE_COMPONENT = "C";
	public static final String TYPE_ARTICLE = "A";
	public static final String TYPE_EXTERNAL_LINK = "EL";

	public Highlight()
	{
	}

	@Override
	public void updateFields(StandardEntity entity)
	{
		super.updateFields(entity);

		Highlight highlight = (Highlight) entity;

		this.setDescription(highlight.getDescription());
		this.setHighlightType(highlight.getHighlightType());
		this.setLink(highlight.getLink());
		this.setTitle(highlight.getTitle());

	}

	public String getHighlightId()
	{
		return highlightId;
	}

	public void setHighlightId(String highlightId)
	{
		this.highlightId = highlightId;
	}

	public String getHighlightType()
	{
		return highlightType;
	}

	public void setHighlightType(String highlightType)
	{
		this.highlightType = highlightType;
	}

	public String getTitle()
	{
		return title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public String getLink()
	{
		return link;
	}

	public void setLink(String link)
	{
		this.link = link;
	}

}

@@ -16,9 +16,9 @@
  201
-4
+5
  Spa
@@ -1338,41 +1338,8 @@
 e;%0A%0A
-/**%0A *%0A * @author dshurtleff%0A */%0A
 @API
@@ -2179,16 +2179,109 @@
  link;%0A%0A
+%09@ConsumeField%0A%09@APIDescription(%22Position when ordered%22)%0A%09private Integer orderingPosition;%0A%0A
 %09public 
@@ -2824,16 +2824,77 @@
 itle());
+%0A%09%09this.setOrderingPosition(highlight.getOrderingPosition());
 %0A%0A%09%7D%0A%0A%09p
@@ -3547,24 +3547,24 @@
 ng link)%0A%09%7B%0A
-
 %09%09this.link 
@@ -3575,10 +3575,192 @@
 nk;%0A%09%7D%0A%0A
+%09public Integer getOrderingPosition()%0A%09%7B%0A%09%09return orderingPosition;%0A%09%7D%0A%0A%09public void setOrderingPosition(Integer orderingPosition)%0A%09%7B%0A%09%09this.orderingPosition = orderingPosition;%0A%09%7D%0A%0A
 %7D%0A

Add orderingPosition field to Hightlight entity