| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | 1 | package org.vostokframework.application.services |
| 30 | |
{ |
| 31 | |
import org.as3collections.IList; |
| 32 | |
import org.as3utils.StringUtil; |
| 33 | |
import org.vostokframework.VostokFramework; |
| 34 | |
import org.vostokframework.VostokIdentification; |
| 35 | |
import org.vostokframework.application.AssetsContext; |
| 36 | |
import org.vostokframework.domain.assets.AssetPackage; |
| 37 | |
import org.vostokframework.domain.assets.errors.AssetPackageNotFoundError; |
| 38 | |
import org.vostokframework.domain.assets.errors.DuplicateAssetPackageError; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public class AssetPackageService |
| 46 | |
{ |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
private var _context: AssetsContext; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public function AssetPackageService() |
| 56 | 1 | { |
| 57 | 1 | _context = AssetsContext.getInstance(); |
| 58 | 1 | } |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public function assetPackageExists(assetPackageId:String, locale:String = null): Boolean |
| 69 | |
{ |
| 70 | 1 | if (StringUtil.isBlank(assetPackageId)) throw new ArgumentError("Argument <assetPackageId> must not be null nor an empty String."); |
| 71 | |
|
| 72 | 1 | if (!locale) locale = VostokFramework.CROSS_LOCALE_ID; |
| 73 | |
|
| 74 | 1 | var identification:VostokIdentification = new VostokIdentification(assetPackageId, locale); |
| 75 | 1 | return _context.assetPackageRepository.exists(identification); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public function createAssetPackage(assetPackageId:String, locale:String = null): AssetPackage |
| 88 | |
{ |
| 89 | 1 | if (StringUtil.isBlank(assetPackageId)) throw new ArgumentError("Argument <assetPackageId> must not be null nor an empty String."); |
| 90 | |
|
| 91 | 1 | if (!locale) locale = VostokFramework.CROSS_LOCALE_ID; |
| 92 | |
|
| 93 | 1 | var identification:VostokIdentification = new VostokIdentification(assetPackageId, locale); |
| 94 | 1 | var assetPackage:AssetPackage = _context.assetPackageFactory.create(identification); |
| 95 | |
|
| 96 | |
try |
| 97 | |
{ |
| 98 | 1 | _context.assetPackageRepository.add(assetPackage); |
| 99 | |
} |
| 100 | 1 | catch(error:DuplicateAssetPackageError) |
| 101 | |
{ |
| 102 | 0 | var message:String = "There is already an AssetPackage object stored with identification: "; |
| 103 | 0 | message += "<" + assetPackage.identification + ">\n"; |
| 104 | 0 | message += "Use the method <AssetPackageService().assetPackageExists()> to check if an AssetPackage object already exists.\n"; |
| 105 | 0 | message += "In addition, make sure you have provided the correct <assetPackageId> and <locale> arguments:\n"; |
| 106 | 0 | message += "Provided <assetPackageId>: " + assetPackageId + "\n"; |
| 107 | 0 | message += "Provided <locale>: " + locale + "\n"; |
| 108 | 0 | message += "Final AssetPackage identification: " + error.identification + "\n"; |
| 109 | 0 | message += "For further information please read the documentation section about the AssetPackage object."; |
| 110 | |
|
| 111 | 0 | throw new DuplicateAssetPackageError(error.identification, message); |
| 112 | |
} |
| 113 | |
|
| 114 | 1 | return assetPackage; |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public function getAllAssetPackages(): IList |
| 123 | |
{ |
| 124 | 1 | return _context.assetPackageRepository.findAll(); |
| 125 | |
} |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
public function getAssetPackage(assetPackageId:String, locale:String = null): AssetPackage |
| 136 | |
{ |
| 137 | 1 | if (StringUtil.isBlank(assetPackageId)) throw new ArgumentError("Argument <assetPackageId> must not be null nor an empty String."); |
| 138 | |
|
| 139 | 1 | if (!locale) locale = VostokFramework.CROSS_LOCALE_ID; |
| 140 | 1 | var identification:VostokIdentification = new VostokIdentification(assetPackageId, locale); |
| 141 | |
|
| 142 | 1 | if (!assetPackageExists(assetPackageId, locale)) |
| 143 | |
{ |
| 144 | 1 | var message:String = "There is no AssetPackage object stored with identification:\n"; |
| 145 | 1 | message += "<" + identification + ">.\n"; |
| 146 | 1 | message += "Use the method <AssetPackageService().assetPackageExists()> to check if an AssetPackage exists.\n"; |
| 147 | 1 | message += "In addition, make sure you have provided the correct <assetPackageId> and <locale> arguments:\n"; |
| 148 | 1 | message += "Provided <assetPackageId>: " + assetPackageId + "\n"; |
| 149 | 1 | message += "Provided <locale>: " + locale + "\n"; |
| 150 | 1 | message += "Final AssetPackage identification: " + identification + "\n"; |
| 151 | 1 | message += "For further information please read the documentation section about the AssetPackage object."; |
| 152 | |
|
| 153 | 1 | throw new AssetPackageNotFoundError(identification, message); |
| 154 | |
} |
| 155 | |
|
| 156 | 1 | return _context.assetPackageRepository.find(identification); |
| 157 | |
} |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
public function removeAllAssetPackages(): void |
| 163 | |
{ |
| 164 | 1 | _context.assetPackageRepository.clear(); |
| 165 | 1 | } |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
public function removeAssetPackage(assetPackageId:String, locale:String = null): Boolean |
| 176 | |
{ |
| 177 | 1 | if (StringUtil.isBlank(assetPackageId)) throw new ArgumentError("Argument <assetPackageId> must not be null nor an empty String."); |
| 178 | |
|
| 179 | 1 | if (!locale) locale = VostokFramework.CROSS_LOCALE_ID; |
| 180 | |
|
| 181 | 1 | var identification:VostokIdentification = new VostokIdentification(assetPackageId, locale); |
| 182 | 1 | return _context.assetPackageRepository.remove(identification); |
| 183 | |
} |
| 184 | |
|
| 185 | |
} |
| 186 | |
|
| 187 | |
} |