001/* 002 * Copyright 2019 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.odfsync.apogee.ws; 017 018import java.util.HashMap; 019import java.util.HashSet; 020import java.util.LinkedHashSet; 021import java.util.Map; 022import java.util.Set; 023 024import org.ametys.cms.repository.Content; 025import org.ametys.plugins.odfsync.apogee.ws.structure.ApogeeExportStructure; 026import org.ametys.runtime.model.ModelItem; 027 028/** 029 * The report for an Apogee export 030 */ 031public class ApogeeExportReport 032{ 033 /** 034 * The status of the export 035 */ 036 public enum ExportStatus 037 { 038 /** Some data from content are invalid (mandatory code, wrong code format) */ 039 CONTENT_DATA_INVALID, 040 041 /** The content structure is invalid */ 042 CONTENT_STRUCTURE_INVALID, 043 044 /** An error occurred during the export */ 045 ERROR, 046 047 /** The export is working */ 048 OK; 049 } 050 051 private ApogeeExportStructure _structure; 052 private Map<Content, Set<ModelItem>> _mandatoryDataByContent; 053 private ExportStatus _exportStatus; 054 private Map<Content, Set<Content>> _missingRelations; 055 056 /** 057 * The constructor 058 */ 059 public ApogeeExportReport() 060 { 061 _mandatoryDataByContent = new HashMap<>(); 062 _missingRelations = new HashMap<>(); 063 } 064 065 /** 066 * The constructor 067 * @param status the export status 068 */ 069 public ApogeeExportReport(ExportStatus status) 070 { 071 _mandatoryDataByContent = new HashMap<>(); 072 _missingRelations = new HashMap<>(); 073 _exportStatus = status; 074 } 075 076 /** 077 * Add mandatory model item for a content 078 * @param content the content 079 * @param modelItem the model item 080 */ 081 public void addMandatoryDataPath(Content content, ModelItem modelItem) 082 { 083 if (!_mandatoryDataByContent.containsKey(content)) 084 { 085 _mandatoryDataByContent.put(content, new HashSet<>()); 086 } 087 088 Set<ModelItem> mandatoryData = _mandatoryDataByContent.get(content); 089 mandatoryData.add(modelItem); 090 } 091 092 /** 093 * Get the mandatory model item by content 094 * @return the map of mandatory model item 095 */ 096 public Map<Content, Set<ModelItem>> getMandatoryDataPathByContent() 097 { 098 return _mandatoryDataByContent; 099 } 100 101 /** 102 * Add the missing relation between a parent and a child content 103 * @param parentContent the parent content 104 * @param childContent the child content 105 */ 106 public void addMissingRelation(Content parentContent, Content childContent) 107 { 108 if (!_missingRelations.containsKey(parentContent)) 109 { 110 _missingRelations.put(parentContent, new LinkedHashSet<>()); 111 } 112 113 Set<Content> missingRelations = _missingRelations.get(parentContent); 114 missingRelations.add(childContent); 115 } 116 117 /** 118 * Get the missing relations 119 * @return the map of missing relation 120 */ 121 public Map<Content, Set<Content>> getMissingRelations() 122 { 123 return _missingRelations; 124 } 125 126 /** 127 * Get the export status 128 * @return the export status 129 */ 130 public ExportStatus getExportStatus() 131 { 132 return _exportStatus; 133 } 134 135 /** 136 * Set the export status 137 * @param status the export status 138 */ 139 public void setExportStatus(ExportStatus status) 140 { 141 _exportStatus = status; 142 } 143 144 /** 145 * Get the apogee structure implementation. 146 * @return the apogee structure implementation 147 */ 148 public ApogeeExportStructure getApogeeExportStructure() 149 { 150 return _structure; 151 } 152 153 /** 154 * Set the apogee structure implementation. 155 * @param structure the apogee structure implementation. 156 */ 157 public void setApogeeExportStructure(ApogeeExportStructure structure) 158 { 159 _structure = structure; 160 } 161}