001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.dataAccess.file; 019 020import io.stallion.dataAccess.MappedModel; 021import io.stallion.dataAccess.StandardDisplayableModel; 022 023import java.time.LocalDateTime; 024import java.time.ZoneId; 025import java.time.ZonedDateTime; 026import java.util.ArrayList; 027import java.util.HashMap; 028import java.util.List; 029import java.util.Map; 030 031import static io.stallion.utils.Literals.map; 032 033 034public class TextItem extends StandardDisplayableModel implements MappedModel { 035 036 private Map<String, Object> attributes = map(); 037 038 private List<String> tags = null; 039 private List<StElement> elements = null; 040 private Map<String, StElement> elementById; 041 042 043 044 045 /*** 046 * Creates a new object with all fields non-null; 047 * @return 048 */ 049 public static TextItem build() { 050 TextItem item1 = new TextItem() 051 .setSlug("dfasf"); 052 TextItem item = new TextItem(); 053 item 054 .setTags(new ArrayList<String>()) 055 .setElementById(new HashMap<>()) 056 .setElements(new ArrayList<>()) 057 .setPublishDate(ZonedDateTime.of(LocalDateTime.now(), ZoneId.of("UTC"))) 058 .setTitle("") 059 .setDraft(false) 060 .setTemplate("") 061 .setContent("") 062 .setSlug("") 063 ; 064 return item; 065 066 } 067 068 069 public List<String> getTags() { 070 return tags; 071 } 072 073 public TextItem setTags(List<String> tags) { 074 this.tags = tags; 075 return this; 076 } 077 078 public List<StElement> getElements() { 079 return elements; 080 } 081 082 public TextItem setElements(List<StElement> elements) { 083 this.elements = elements; 084 return this; 085 } 086 087 public Map<String, StElement> getElementById() { 088 return elementById; 089 } 090 091 public TextItem setElementById(Map<String, StElement> elementById) { 092 this.elementById = elementById; 093 return this; 094 } 095 096 public Integer getYear() { 097 return getPublishDate().getYear(); 098 } 099 100 public Integer getMonth() { 101 return getPublishDate().getMonth().getValue(); 102 } 103 104 105 106 107 @Override 108 public Map<String, Object> getAttributes() { 109 return attributes; 110 } 111 112 @Override 113 public void setAttributes(Map<String, Object> attributes) { 114 this.attributes = attributes; 115 } 116}