Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.anotheria.anosite.gen.asresourcedata.service.fixture.ASResourceDataServiceFixtureImpl Maven / Gradle / Ivy
/**
********************************************************************************
*** ASResourceDataServiceFixtureImpl.java ***
*** The implementation of the IASResourceDataService for unit testing. ***
*** generated by AnoSiteGenerator (ASG), Version: 2.6.3 ***
*** Copyright (C) 2005 - 2010 Anotheria.net, www.anotheria.net ***
*** All Rights Reserved. ***
********************************************************************************
*** Don't edit this code, if you aren't sure ***
*** that you do exactly know what you are doing! ***
*** It's better to invest time in the generator, as into the generated code. ***
********************************************************************************
*/
package net.anotheria.anosite.gen.asresourcedata.service.fixture;
import java.util.List;
import java.util.Set;
import net.anotheria.util.sorter.SortType;
import net.anotheria.util.sorter.StaticQuickSorter;
import net.anotheria.util.slicer.Segment;
import net.anotheria.util.slicer.Slicer;
import net.anotheria.anodoc.query2.DocumentQuery;
import net.anotheria.anodoc.query2.QueryResult;
import net.anotheria.anodoc.query2.QueryResultEntry;
import net.anotheria.anodoc.query2.QueryProperty;
import net.anotheria.util.xml.XMLNode;
import net.anotheria.util.xml.XMLAttribute;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import net.anotheria.anosite.gen.shared.util.DocumentName;
import net.anotheria.anosite.gen.asresourcedata.service.IASResourceDataService;
import net.anotheria.anosite.gen.asresourcedata.service.ASResourceDataServiceException;
import net.anotheria.asg.service.BaseFixtureService;
import net.anotheria.asg.service.IFixtureService;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.ArrayList;
import net.anotheria.anosite.gen.asresourcedata.data.TextResource;
import net.anotheria.anosite.gen.asresourcedata.data.TextResourceXMLHelper;
import net.anotheria.anosite.gen.asresourcedata.data.TextResourceDocument;
import net.anotheria.anosite.gen.asresourcedata.data.LocalizationBundle;
import net.anotheria.anosite.gen.asresourcedata.data.LocalizationBundleXMLHelper;
import net.anotheria.anosite.gen.asresourcedata.data.LocalizationBundleDocument;
import net.anotheria.anosite.gen.asresourcedata.data.MailTemplate;
import net.anotheria.anosite.gen.asresourcedata.data.MailTemplateXMLHelper;
import net.anotheria.anosite.gen.asresourcedata.data.MailTemplateDocument;
import net.anotheria.anosite.gen.asresourcedata.data.Image;
import net.anotheria.anosite.gen.asresourcedata.data.ImageXMLHelper;
import net.anotheria.anosite.gen.asresourcedata.data.ImageDocument;
import net.anotheria.anosite.gen.asresourcedata.data.FileLink;
import net.anotheria.anosite.gen.asresourcedata.data.FileLinkXMLHelper;
import net.anotheria.anosite.gen.asresourcedata.data.FileLinkDocument;
public class ASResourceDataServiceFixtureImpl extends BaseFixtureService implements IASResourceDataService, IFixtureService{
private static ASResourceDataServiceFixtureImpl instance;
private Map textresourceMap;
private AtomicInteger textresourceIdHolder;
private Map localizationbundleMap;
private AtomicInteger localizationbundleIdHolder;
private Map mailtemplateMap;
private AtomicInteger mailtemplateIdHolder;
private Map imageMap;
private AtomicInteger imageIdHolder;
private Map filelinkMap;
private AtomicInteger filelinkIdHolder;
private ASResourceDataServiceFixtureImpl(){
reset();
addServiceListener(new net.anotheria.anosite.cms.listener.CRUDLogListener());
addServiceListener(new net.anotheria.anosite.cms.listener.AsResourceListener());
}
static final ASResourceDataServiceFixtureImpl getInstance(){
if (instance==null){
instance = new ASResourceDataServiceFixtureImpl();
}
return instance;
}
@Override public void reset(){
textresourceMap = new ConcurrentHashMap();
textresourceIdHolder = new AtomicInteger(0);
localizationbundleMap = new ConcurrentHashMap();
localizationbundleIdHolder = new AtomicInteger(0);
mailtemplateMap = new ConcurrentHashMap();
mailtemplateIdHolder = new AtomicInteger(0);
imageMap = new ConcurrentHashMap();
imageIdHolder = new AtomicInteger(0);
filelinkMap = new ConcurrentHashMap();
filelinkIdHolder = new AtomicInteger(0);
}
@Override public List getTextResources() throws ASResourceDataServiceException {
List ret = new ArrayList();
ret.addAll(textresourceMap.values());
return ret;
}
@Override public List getTextResources(SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getTextResources(), sortType);
}
@Override public void deleteTextResource(TextResource textresource) throws ASResourceDataServiceException {
deleteTextResource(textresource.getId());
}
@Override public void deleteTextResource(String id) throws ASResourceDataServiceException {
TextResource old = textresourceMap.remove(id);
if (old!=null){
fireObjectDeletedEvent(old);
}
}
/**
* Deletes multiple TextResource objects.
*/
@Override public void deleteTextResources(List list) throws ASResourceDataServiceException {
for (TextResource textresource : list){
deleteTextResource(textresource);
}
}
@Override public TextResource getTextResource(String id) throws ASResourceDataServiceException {
TextResource textresource = textresourceMap.get(id);
if (textresource==null)
throw new ASResourceDataServiceException("No TextResource with id "+id+" found");
return textresource;
}
@Override public TextResource importTextResource(TextResource textresource) throws ASResourceDataServiceException {
textresourceMap.put(textresource.getId(), textresource);
return textresource;
}
@Override public List importTextResources(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (TextResource textresource : list)
ret.add(importTextResource(textresource));
return ret;
}
@Override public TextResource createTextResource(TextResource textresource) throws ASResourceDataServiceException {
String nextId = ""+textresourceIdHolder.incrementAndGet();;
// //CMS Specific code
TextResourceDocument newTextresource = (TextResourceDocument)textresource;
newTextresource.renameTo(nextId);
textresourceMap.put(newTextresource.getId(), newTextresource);
fireObjectCreatedEvent(newTextresource);
return newTextresource;
}
/**
* Creates multiple new TextResource objects.
* Returns the created versions.
*/
@Override public List createTextResources(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (TextResource textresource : list)
ret.add(createTextResource(textresource));
return ret;
}
/**
* Updates multiple new TextResource objects.
* Returns the updated versions.
*/
@Override public List updateTextResources(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (TextResource textresource : list)
ret.add(updateTextResource(textresource));
return ret;
}
@Override public TextResource updateTextResource(TextResource textresource) throws ASResourceDataServiceException {
TextResource oldVersion = textresourceMap.put(textresource.getId(), textresource);
if (oldVersion!=null){
fireObjectUpdatedEvent(oldVersion, textresource);
}
return textresource;
}
@Override public List getTextResourcesByProperty(String propertyName, Object value) throws ASResourceDataServiceException {
List list = getTextResources();
List ret = new ArrayList();
for (TextResource textresource : list){
Object propertyValue = textresource.getPropertyValue(propertyName);
if (propertyValue!=null && propertyValue.equals(value))
ret.add(textresource);
}
return ret;
}
@Override public List getTextResourcesByProperty(String propertyName, Object value, SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getTextResourcesByProperty(propertyName, value), sortType);
}
/**
* Executes a query on TextResources
*/
@Override public QueryResult executeQueryOnTextResources(DocumentQuery query) throws ASResourceDataServiceException {
List allTextResources = getTextResources();
QueryResult result = new QueryResult();
for (int i=0; i partialResult = query.match(allTextResources.get(i));
result.add(partialResult);
}
return result;
}
/**
* Returns all TextResource objects, where property matches.
*/
@Override public List getTextResourcesByProperty(QueryProperty... properties) throws ASResourceDataServiceException {;
List list = getTextResources();
if (properties==null || properties.length==0)
return list;
List ret = new ArrayList();
for (TextResource textresource : list){
boolean mayPass = true;
for (QueryProperty p : properties){
Object propertyValue = textresource.getPropertyValue(p.getName());
if (mayPass && (propertyValue==null || (!(p.doesMatch(propertyValue)))))
mayPass = false;
}
if (mayPass)
ret.add(textresource);
}
return ret;
}
/**
* Returns all TextResource objects, where property matches, sorted
*/
@Override public List getTextResourcesByProperty(SortType sortType, QueryProperty... property) throws ASResourceDataServiceException {;
return StaticQuickSorter.sort(getTextResourcesByProperty(property), sortType);
}
/**
* Returns TextResource objects count.
*/
@Override public int getTextResourcesCount() throws ASResourceDataServiceException {
return textresourceMap.values().size();
}
/**
* Returns TextResource objects segment.
*/
public List getTextResources(Segment aSegment) throws ASResourceDataServiceException {
return Slicer.slice(aSegment, getTextResources()).getSliceData();
}
/**
* Returns TextResource objects segment, where property matched.
*/
public List getTextResourcesByProperty(Segment aSegment, QueryProperty... property) {
int pLimit = aSegment.getElementsPerSlice();
int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
List ret = new ArrayList();
List src = new ArrayList();
src.addAll(textresourceMap.values());
for (TextResource textresource : src) {;
boolean mayPass = true;
for (QueryProperty qp : property) {;
mayPass = mayPass && qp.doesMatch(textresource.getPropertyValue(qp.getName()));
}
if (mayPass)
ret.add(textresource);
if (ret.size() > pOffset + pLimit)
break;
}
return Slicer.slice(aSegment, ret).getSliceData();
}
/**
* Returns TextResource objects segment, where property matched, sorted.
*/
public List getTextResourcesByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
return StaticQuickSorter.sort(getTextResourcesByProperty(aSegment, aProperty), aSortType);
}
@Override public List getLocalizationBundles() throws ASResourceDataServiceException {
List ret = new ArrayList();
ret.addAll(localizationbundleMap.values());
return ret;
}
@Override public List getLocalizationBundles(SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getLocalizationBundles(), sortType);
}
@Override public void deleteLocalizationBundle(LocalizationBundle localizationbundle) throws ASResourceDataServiceException {
deleteLocalizationBundle(localizationbundle.getId());
}
@Override public void deleteLocalizationBundle(String id) throws ASResourceDataServiceException {
LocalizationBundle old = localizationbundleMap.remove(id);
if (old!=null){
fireObjectDeletedEvent(old);
}
}
/**
* Deletes multiple LocalizationBundle objects.
*/
@Override public void deleteLocalizationBundles(List list) throws ASResourceDataServiceException {
for (LocalizationBundle localizationbundle : list){
deleteLocalizationBundle(localizationbundle);
}
}
@Override public LocalizationBundle getLocalizationBundle(String id) throws ASResourceDataServiceException {
LocalizationBundle localizationbundle = localizationbundleMap.get(id);
if (localizationbundle==null)
throw new ASResourceDataServiceException("No LocalizationBundle with id "+id+" found");
return localizationbundle;
}
@Override public LocalizationBundle importLocalizationBundle(LocalizationBundle localizationbundle) throws ASResourceDataServiceException {
localizationbundleMap.put(localizationbundle.getId(), localizationbundle);
return localizationbundle;
}
@Override public List importLocalizationBundles(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (LocalizationBundle localizationbundle : list)
ret.add(importLocalizationBundle(localizationbundle));
return ret;
}
@Override public LocalizationBundle createLocalizationBundle(LocalizationBundle localizationbundle) throws ASResourceDataServiceException {
String nextId = ""+localizationbundleIdHolder.incrementAndGet();;
// //CMS Specific code
LocalizationBundleDocument newLocalizationbundle = (LocalizationBundleDocument)localizationbundle;
newLocalizationbundle.renameTo(nextId);
localizationbundleMap.put(newLocalizationbundle.getId(), newLocalizationbundle);
fireObjectCreatedEvent(newLocalizationbundle);
return newLocalizationbundle;
}
/**
* Creates multiple new LocalizationBundle objects.
* Returns the created versions.
*/
@Override public List createLocalizationBundles(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (LocalizationBundle localizationbundle : list)
ret.add(createLocalizationBundle(localizationbundle));
return ret;
}
/**
* Updates multiple new LocalizationBundle objects.
* Returns the updated versions.
*/
@Override public List updateLocalizationBundles(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (LocalizationBundle localizationbundle : list)
ret.add(updateLocalizationBundle(localizationbundle));
return ret;
}
@Override public LocalizationBundle updateLocalizationBundle(LocalizationBundle localizationbundle) throws ASResourceDataServiceException {
LocalizationBundle oldVersion = localizationbundleMap.put(localizationbundle.getId(), localizationbundle);
if (oldVersion!=null){
fireObjectUpdatedEvent(oldVersion, localizationbundle);
}
return localizationbundle;
}
@Override public List getLocalizationBundlesByProperty(String propertyName, Object value) throws ASResourceDataServiceException {
List list = getLocalizationBundles();
List ret = new ArrayList();
for (LocalizationBundle localizationbundle : list){
Object propertyValue = localizationbundle.getPropertyValue(propertyName);
if (propertyValue!=null && propertyValue.equals(value))
ret.add(localizationbundle);
}
return ret;
}
@Override public List getLocalizationBundlesByProperty(String propertyName, Object value, SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getLocalizationBundlesByProperty(propertyName, value), sortType);
}
/**
* Executes a query on LocalizationBundles
*/
@Override public QueryResult executeQueryOnLocalizationBundles(DocumentQuery query) throws ASResourceDataServiceException {
List allLocalizationBundles = getLocalizationBundles();
QueryResult result = new QueryResult();
for (int i=0; i partialResult = query.match(allLocalizationBundles.get(i));
result.add(partialResult);
}
return result;
}
/**
* Returns all LocalizationBundle objects, where property matches.
*/
@Override public List getLocalizationBundlesByProperty(QueryProperty... properties) throws ASResourceDataServiceException {;
List list = getLocalizationBundles();
if (properties==null || properties.length==0)
return list;
List ret = new ArrayList();
for (LocalizationBundle localizationbundle : list){
boolean mayPass = true;
for (QueryProperty p : properties){
Object propertyValue = localizationbundle.getPropertyValue(p.getName());
if (mayPass && (propertyValue==null || (!(p.doesMatch(propertyValue)))))
mayPass = false;
}
if (mayPass)
ret.add(localizationbundle);
}
return ret;
}
/**
* Returns all LocalizationBundle objects, where property matches, sorted
*/
@Override public List getLocalizationBundlesByProperty(SortType sortType, QueryProperty... property) throws ASResourceDataServiceException {;
return StaticQuickSorter.sort(getLocalizationBundlesByProperty(property), sortType);
}
/**
* Returns LocalizationBundle objects count.
*/
@Override public int getLocalizationBundlesCount() throws ASResourceDataServiceException {
return localizationbundleMap.values().size();
}
/**
* Returns LocalizationBundle objects segment.
*/
public List getLocalizationBundles(Segment aSegment) throws ASResourceDataServiceException {
return Slicer.slice(aSegment, getLocalizationBundles()).getSliceData();
}
/**
* Returns LocalizationBundle objects segment, where property matched.
*/
public List getLocalizationBundlesByProperty(Segment aSegment, QueryProperty... property) {
int pLimit = aSegment.getElementsPerSlice();
int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
List ret = new ArrayList();
List src = new ArrayList();
src.addAll(localizationbundleMap.values());
for (LocalizationBundle localizationbundle : src) {;
boolean mayPass = true;
for (QueryProperty qp : property) {;
mayPass = mayPass && qp.doesMatch(localizationbundle.getPropertyValue(qp.getName()));
}
if (mayPass)
ret.add(localizationbundle);
if (ret.size() > pOffset + pLimit)
break;
}
return Slicer.slice(aSegment, ret).getSliceData();
}
/**
* Returns LocalizationBundle objects segment, where property matched, sorted.
*/
public List getLocalizationBundlesByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
return StaticQuickSorter.sort(getLocalizationBundlesByProperty(aSegment, aProperty), aSortType);
}
@Override public List getMailTemplates() throws ASResourceDataServiceException {
List ret = new ArrayList();
ret.addAll(mailtemplateMap.values());
return ret;
}
@Override public List getMailTemplates(SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getMailTemplates(), sortType);
}
@Override public void deleteMailTemplate(MailTemplate mailtemplate) throws ASResourceDataServiceException {
deleteMailTemplate(mailtemplate.getId());
}
@Override public void deleteMailTemplate(String id) throws ASResourceDataServiceException {
MailTemplate old = mailtemplateMap.remove(id);
if (old!=null){
fireObjectDeletedEvent(old);
}
}
/**
* Deletes multiple MailTemplate objects.
*/
@Override public void deleteMailTemplates(List list) throws ASResourceDataServiceException {
for (MailTemplate mailtemplate : list){
deleteMailTemplate(mailtemplate);
}
}
@Override public MailTemplate getMailTemplate(String id) throws ASResourceDataServiceException {
MailTemplate mailtemplate = mailtemplateMap.get(id);
if (mailtemplate==null)
throw new ASResourceDataServiceException("No MailTemplate with id "+id+" found");
return mailtemplate;
}
@Override public MailTemplate importMailTemplate(MailTemplate mailtemplate) throws ASResourceDataServiceException {
mailtemplateMap.put(mailtemplate.getId(), mailtemplate);
return mailtemplate;
}
@Override public List importMailTemplates(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (MailTemplate mailtemplate : list)
ret.add(importMailTemplate(mailtemplate));
return ret;
}
@Override public MailTemplate createMailTemplate(MailTemplate mailtemplate) throws ASResourceDataServiceException {
String nextId = ""+mailtemplateIdHolder.incrementAndGet();;
// //CMS Specific code
MailTemplateDocument newMailtemplate = (MailTemplateDocument)mailtemplate;
newMailtemplate.renameTo(nextId);
mailtemplateMap.put(newMailtemplate.getId(), newMailtemplate);
fireObjectCreatedEvent(newMailtemplate);
return newMailtemplate;
}
/**
* Creates multiple new MailTemplate objects.
* Returns the created versions.
*/
@Override public List createMailTemplates(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (MailTemplate mailtemplate : list)
ret.add(createMailTemplate(mailtemplate));
return ret;
}
/**
* Updates multiple new MailTemplate objects.
* Returns the updated versions.
*/
@Override public List updateMailTemplates(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (MailTemplate mailtemplate : list)
ret.add(updateMailTemplate(mailtemplate));
return ret;
}
@Override public MailTemplate updateMailTemplate(MailTemplate mailtemplate) throws ASResourceDataServiceException {
MailTemplate oldVersion = mailtemplateMap.put(mailtemplate.getId(), mailtemplate);
if (oldVersion!=null){
fireObjectUpdatedEvent(oldVersion, mailtemplate);
}
return mailtemplate;
}
@Override public List getMailTemplatesByProperty(String propertyName, Object value) throws ASResourceDataServiceException {
List list = getMailTemplates();
List ret = new ArrayList();
for (MailTemplate mailtemplate : list){
Object propertyValue = mailtemplate.getPropertyValue(propertyName);
if (propertyValue!=null && propertyValue.equals(value))
ret.add(mailtemplate);
}
return ret;
}
@Override public List getMailTemplatesByProperty(String propertyName, Object value, SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getMailTemplatesByProperty(propertyName, value), sortType);
}
/**
* Executes a query on MailTemplates
*/
@Override public QueryResult executeQueryOnMailTemplates(DocumentQuery query) throws ASResourceDataServiceException {
List allMailTemplates = getMailTemplates();
QueryResult result = new QueryResult();
for (int i=0; i partialResult = query.match(allMailTemplates.get(i));
result.add(partialResult);
}
return result;
}
/**
* Returns all MailTemplate objects, where property matches.
*/
@Override public List getMailTemplatesByProperty(QueryProperty... properties) throws ASResourceDataServiceException {;
List list = getMailTemplates();
if (properties==null || properties.length==0)
return list;
List ret = new ArrayList();
for (MailTemplate mailtemplate : list){
boolean mayPass = true;
for (QueryProperty p : properties){
Object propertyValue = mailtemplate.getPropertyValue(p.getName());
if (mayPass && (propertyValue==null || (!(p.doesMatch(propertyValue)))))
mayPass = false;
}
if (mayPass)
ret.add(mailtemplate);
}
return ret;
}
/**
* Returns all MailTemplate objects, where property matches, sorted
*/
@Override public List getMailTemplatesByProperty(SortType sortType, QueryProperty... property) throws ASResourceDataServiceException {;
return StaticQuickSorter.sort(getMailTemplatesByProperty(property), sortType);
}
/**
* Returns MailTemplate objects count.
*/
@Override public int getMailTemplatesCount() throws ASResourceDataServiceException {
return mailtemplateMap.values().size();
}
/**
* Returns MailTemplate objects segment.
*/
public List getMailTemplates(Segment aSegment) throws ASResourceDataServiceException {
return Slicer.slice(aSegment, getMailTemplates()).getSliceData();
}
/**
* Returns MailTemplate objects segment, where property matched.
*/
public List getMailTemplatesByProperty(Segment aSegment, QueryProperty... property) {
int pLimit = aSegment.getElementsPerSlice();
int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
List ret = new ArrayList();
List src = new ArrayList();
src.addAll(mailtemplateMap.values());
for (MailTemplate mailtemplate : src) {;
boolean mayPass = true;
for (QueryProperty qp : property) {;
mayPass = mayPass && qp.doesMatch(mailtemplate.getPropertyValue(qp.getName()));
}
if (mayPass)
ret.add(mailtemplate);
if (ret.size() > pOffset + pLimit)
break;
}
return Slicer.slice(aSegment, ret).getSliceData();
}
/**
* Returns MailTemplate objects segment, where property matched, sorted.
*/
public List getMailTemplatesByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
return StaticQuickSorter.sort(getMailTemplatesByProperty(aSegment, aProperty), aSortType);
}
@Override public List getImages() throws ASResourceDataServiceException {
List ret = new ArrayList();
ret.addAll(imageMap.values());
return ret;
}
@Override public List getImages(SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getImages(), sortType);
}
@Override public void deleteImage(Image image) throws ASResourceDataServiceException {
deleteImage(image.getId());
}
@Override public void deleteImage(String id) throws ASResourceDataServiceException {
Image old = imageMap.remove(id);
if (old!=null){
fireObjectDeletedEvent(old);
}
}
/**
* Deletes multiple Image objects.
*/
@Override public void deleteImages(List list) throws ASResourceDataServiceException {
for (Image image : list){
deleteImage(image);
}
}
@Override public Image getImage(String id) throws ASResourceDataServiceException {
Image image = imageMap.get(id);
if (image==null)
throw new ASResourceDataServiceException("No Image with id "+id+" found");
return image;
}
@Override public Image importImage(Image image) throws ASResourceDataServiceException {
imageMap.put(image.getId(), image);
return image;
}
@Override public List importImages(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (Image image : list)
ret.add(importImage(image));
return ret;
}
@Override public Image createImage(Image image) throws ASResourceDataServiceException {
String nextId = ""+imageIdHolder.incrementAndGet();;
// //CMS Specific code
ImageDocument newImage = (ImageDocument)image;
newImage.renameTo(nextId);
imageMap.put(newImage.getId(), newImage);
fireObjectCreatedEvent(newImage);
return newImage;
}
/**
* Creates multiple new Image objects.
* Returns the created versions.
*/
@Override public List createImages(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (Image image : list)
ret.add(createImage(image));
return ret;
}
/**
* Updates multiple new Image objects.
* Returns the updated versions.
*/
@Override public List updateImages(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (Image image : list)
ret.add(updateImage(image));
return ret;
}
@Override public Image updateImage(Image image) throws ASResourceDataServiceException {
Image oldVersion = imageMap.put(image.getId(), image);
if (oldVersion!=null){
fireObjectUpdatedEvent(oldVersion, image);
}
return image;
}
@Override public List getImagesByProperty(String propertyName, Object value) throws ASResourceDataServiceException {
List list = getImages();
List ret = new ArrayList();
for (Image image : list){
Object propertyValue = image.getPropertyValue(propertyName);
if (propertyValue!=null && propertyValue.equals(value))
ret.add(image);
}
return ret;
}
@Override public List getImagesByProperty(String propertyName, Object value, SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getImagesByProperty(propertyName, value), sortType);
}
/**
* Executes a query on Images
*/
@Override public QueryResult executeQueryOnImages(DocumentQuery query) throws ASResourceDataServiceException {
List allImages = getImages();
QueryResult result = new QueryResult();
for (int i=0; i partialResult = query.match(allImages.get(i));
result.add(partialResult);
}
return result;
}
/**
* Returns all Image objects, where property matches.
*/
@Override public List getImagesByProperty(QueryProperty... properties) throws ASResourceDataServiceException {;
List list = getImages();
if (properties==null || properties.length==0)
return list;
List ret = new ArrayList();
for (Image image : list){
boolean mayPass = true;
for (QueryProperty p : properties){
Object propertyValue = image.getPropertyValue(p.getName());
if (mayPass && (propertyValue==null || (!(p.doesMatch(propertyValue)))))
mayPass = false;
}
if (mayPass)
ret.add(image);
}
return ret;
}
/**
* Returns all Image objects, where property matches, sorted
*/
@Override public List getImagesByProperty(SortType sortType, QueryProperty... property) throws ASResourceDataServiceException {;
return StaticQuickSorter.sort(getImagesByProperty(property), sortType);
}
/**
* Returns Image objects count.
*/
@Override public int getImagesCount() throws ASResourceDataServiceException {
return imageMap.values().size();
}
/**
* Returns Image objects segment.
*/
public List getImages(Segment aSegment) throws ASResourceDataServiceException {
return Slicer.slice(aSegment, getImages()).getSliceData();
}
/**
* Returns Image objects segment, where property matched.
*/
public List getImagesByProperty(Segment aSegment, QueryProperty... property) {
int pLimit = aSegment.getElementsPerSlice();
int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
List ret = new ArrayList();
List src = new ArrayList();
src.addAll(imageMap.values());
for (Image image : src) {;
boolean mayPass = true;
for (QueryProperty qp : property) {;
mayPass = mayPass && qp.doesMatch(image.getPropertyValue(qp.getName()));
}
if (mayPass)
ret.add(image);
if (ret.size() > pOffset + pLimit)
break;
}
return Slicer.slice(aSegment, ret).getSliceData();
}
/**
* Returns Image objects segment, where property matched, sorted.
*/
public List getImagesByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
return StaticQuickSorter.sort(getImagesByProperty(aSegment, aProperty), aSortType);
}
@Override public List getFileLinks() throws ASResourceDataServiceException {
List ret = new ArrayList();
ret.addAll(filelinkMap.values());
return ret;
}
@Override public List getFileLinks(SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getFileLinks(), sortType);
}
@Override public void deleteFileLink(FileLink filelink) throws ASResourceDataServiceException {
deleteFileLink(filelink.getId());
}
@Override public void deleteFileLink(String id) throws ASResourceDataServiceException {
FileLink old = filelinkMap.remove(id);
if (old!=null){
fireObjectDeletedEvent(old);
}
}
/**
* Deletes multiple FileLink objects.
*/
@Override public void deleteFileLinks(List list) throws ASResourceDataServiceException {
for (FileLink filelink : list){
deleteFileLink(filelink);
}
}
@Override public FileLink getFileLink(String id) throws ASResourceDataServiceException {
FileLink filelink = filelinkMap.get(id);
if (filelink==null)
throw new ASResourceDataServiceException("No FileLink with id "+id+" found");
return filelink;
}
@Override public FileLink importFileLink(FileLink filelink) throws ASResourceDataServiceException {
filelinkMap.put(filelink.getId(), filelink);
return filelink;
}
@Override public List importFileLinks(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (FileLink filelink : list)
ret.add(importFileLink(filelink));
return ret;
}
@Override public FileLink createFileLink(FileLink filelink) throws ASResourceDataServiceException {
String nextId = ""+filelinkIdHolder.incrementAndGet();;
// //CMS Specific code
FileLinkDocument newFilelink = (FileLinkDocument)filelink;
newFilelink.renameTo(nextId);
filelinkMap.put(newFilelink.getId(), newFilelink);
fireObjectCreatedEvent(newFilelink);
return newFilelink;
}
/**
* Creates multiple new FileLink objects.
* Returns the created versions.
*/
@Override public List createFileLinks(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (FileLink filelink : list)
ret.add(createFileLink(filelink));
return ret;
}
/**
* Updates multiple new FileLink objects.
* Returns the updated versions.
*/
@Override public List updateFileLinks(List list) throws ASResourceDataServiceException {
List ret = new ArrayList();
for (FileLink filelink : list)
ret.add(updateFileLink(filelink));
return ret;
}
@Override public FileLink updateFileLink(FileLink filelink) throws ASResourceDataServiceException {
FileLink oldVersion = filelinkMap.put(filelink.getId(), filelink);
if (oldVersion!=null){
fireObjectUpdatedEvent(oldVersion, filelink);
}
return filelink;
}
@Override public List getFileLinksByProperty(String propertyName, Object value) throws ASResourceDataServiceException {
List list = getFileLinks();
List ret = new ArrayList();
for (FileLink filelink : list){
Object propertyValue = filelink.getPropertyValue(propertyName);
if (propertyValue!=null && propertyValue.equals(value))
ret.add(filelink);
}
return ret;
}
@Override public List getFileLinksByProperty(String propertyName, Object value, SortType sortType) throws ASResourceDataServiceException {
return StaticQuickSorter.sort(getFileLinksByProperty(propertyName, value), sortType);
}
/**
* Executes a query on FileLinks
*/
@Override public QueryResult executeQueryOnFileLinks(DocumentQuery query) throws ASResourceDataServiceException {
List allFileLinks = getFileLinks();
QueryResult result = new QueryResult();
for (int i=0; i partialResult = query.match(allFileLinks.get(i));
result.add(partialResult);
}
return result;
}
/**
* Returns all FileLink objects, where property matches.
*/
@Override public List getFileLinksByProperty(QueryProperty... properties) throws ASResourceDataServiceException {;
List list = getFileLinks();
if (properties==null || properties.length==0)
return list;
List ret = new ArrayList();
for (FileLink filelink : list){
boolean mayPass = true;
for (QueryProperty p : properties){
Object propertyValue = filelink.getPropertyValue(p.getName());
if (mayPass && (propertyValue==null || (!(p.doesMatch(propertyValue)))))
mayPass = false;
}
if (mayPass)
ret.add(filelink);
}
return ret;
}
/**
* Returns all FileLink objects, where property matches, sorted
*/
@Override public List getFileLinksByProperty(SortType sortType, QueryProperty... property) throws ASResourceDataServiceException {;
return StaticQuickSorter.sort(getFileLinksByProperty(property), sortType);
}
/**
* Returns FileLink objects count.
*/
@Override public int getFileLinksCount() throws ASResourceDataServiceException {
return filelinkMap.values().size();
}
/**
* Returns FileLink objects segment.
*/
public List getFileLinks(Segment aSegment) throws ASResourceDataServiceException {
return Slicer.slice(aSegment, getFileLinks()).getSliceData();
}
/**
* Returns FileLink objects segment, where property matched.
*/
public List getFileLinksByProperty(Segment aSegment, QueryProperty... property) {
int pLimit = aSegment.getElementsPerSlice();
int pOffset = aSegment.getSliceNumber() * aSegment.getElementsPerSlice() - aSegment.getElementsPerSlice();
List ret = new ArrayList();
List src = new ArrayList();
src.addAll(filelinkMap.values());
for (FileLink filelink : src) {;
boolean mayPass = true;
for (QueryProperty qp : property) {;
mayPass = mayPass && qp.doesMatch(filelink.getPropertyValue(qp.getName()));
}
if (mayPass)
ret.add(filelink);
if (ret.size() > pOffset + pLimit)
break;
}
return Slicer.slice(aSegment, ret).getSliceData();
}
/**
* Returns FileLink objects segment, where property matched, sorted.
*/
public List getFileLinksByProperty(Segment aSegment, SortType aSortType, QueryProperty... aProperty){
return StaticQuickSorter.sort(getFileLinksByProperty(aSegment, aProperty), aSortType);
}
public XMLNode exportTextResourcesToXML(){
XMLNode ret = new XMLNode("TextResources");
try{
List list = getTextResources();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (TextResource object : list)
ret.addChildNode(TextResourceXMLHelper.toXML(object));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportTextResourcesToXML() failure: " , e);
}
}
public XMLNode exportTextResourcesToXML(List list){
XMLNode ret = new XMLNode("TextResources");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (TextResource object : list)
ret.addChildNode(TextResourceXMLHelper.toXML(object));
return ret;
}
public XMLNode exportTextResourcesToXML(String languages[]){
XMLNode ret = new XMLNode("TextResources");
try{
List list = getTextResources();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (TextResource object : list)
ret.addChildNode(TextResourceXMLHelper.toXML(object, languages));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportTextResourcesToXML() failure: " , e);
}
}
public XMLNode exportTextResourcesToXML(String languages[], List list){
XMLNode ret = new XMLNode("TextResources");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (TextResource object : list)
ret.addChildNode(TextResourceXMLHelper.toXML(object, languages));
return ret;
}
public void fetchTextResource (final String id, Set addedDocuments, JSONArray data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
// This method is not very fast, since it makes an update (eff. save) after each doc.
public void copyMultilingualAttributesInAllTextResources(String sourceLanguage, String targetLanguage){
throw new AssertionError("Not implemented");
}
public XMLNode exportLocalizationBundlesToXML(){
XMLNode ret = new XMLNode("LocalizationBundles");
try{
List list = getLocalizationBundles();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (LocalizationBundle object : list)
ret.addChildNode(LocalizationBundleXMLHelper.toXML(object));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportLocalizationBundlesToXML() failure: " , e);
}
}
public XMLNode exportLocalizationBundlesToXML(List list){
XMLNode ret = new XMLNode("LocalizationBundles");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (LocalizationBundle object : list)
ret.addChildNode(LocalizationBundleXMLHelper.toXML(object));
return ret;
}
public XMLNode exportLocalizationBundlesToXML(String languages[]){
XMLNode ret = new XMLNode("LocalizationBundles");
try{
List list = getLocalizationBundles();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (LocalizationBundle object : list)
ret.addChildNode(LocalizationBundleXMLHelper.toXML(object, languages));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportLocalizationBundlesToXML() failure: " , e);
}
}
public XMLNode exportLocalizationBundlesToXML(String languages[], List list){
XMLNode ret = new XMLNode("LocalizationBundles");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (LocalizationBundle object : list)
ret.addChildNode(LocalizationBundleXMLHelper.toXML(object, languages));
return ret;
}
public void fetchLocalizationBundle (final String id, Set addedDocuments, JSONArray data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
// This method is not very fast, since it makes an update (eff. save) after each doc.
public void copyMultilingualAttributesInAllLocalizationBundles(String sourceLanguage, String targetLanguage){
throw new AssertionError("Not implemented");
}
public XMLNode exportMailTemplatesToXML(){
XMLNode ret = new XMLNode("MailTemplates");
try{
List list = getMailTemplates();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (MailTemplate object : list)
ret.addChildNode(MailTemplateXMLHelper.toXML(object));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportMailTemplatesToXML() failure: " , e);
}
}
public XMLNode exportMailTemplatesToXML(List list){
XMLNode ret = new XMLNode("MailTemplates");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (MailTemplate object : list)
ret.addChildNode(MailTemplateXMLHelper.toXML(object));
return ret;
}
public XMLNode exportMailTemplatesToXML(String languages[]){
XMLNode ret = new XMLNode("MailTemplates");
try{
List list = getMailTemplates();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (MailTemplate object : list)
ret.addChildNode(MailTemplateXMLHelper.toXML(object, languages));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportMailTemplatesToXML() failure: " , e);
}
}
public XMLNode exportMailTemplatesToXML(String languages[], List list){
XMLNode ret = new XMLNode("MailTemplates");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (MailTemplate object : list)
ret.addChildNode(MailTemplateXMLHelper.toXML(object, languages));
return ret;
}
public void fetchMailTemplate (final String id, Set addedDocuments, JSONArray data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
// This method is not very fast, since it makes an update (eff. save) after each doc.
public void copyMultilingualAttributesInAllMailTemplates(String sourceLanguage, String targetLanguage){
throw new AssertionError("Not implemented");
}
public XMLNode exportImagesToXML(){
XMLNode ret = new XMLNode("Images");
try{
List list = getImages();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (Image object : list)
ret.addChildNode(ImageXMLHelper.toXML(object));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportImagesToXML() failure: " , e);
}
}
public XMLNode exportImagesToXML(List list){
XMLNode ret = new XMLNode("Images");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (Image object : list)
ret.addChildNode(ImageXMLHelper.toXML(object));
return ret;
}
public XMLNode exportImagesToXML(String languages[]){
XMLNode ret = new XMLNode("Images");
try{
List list = getImages();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (Image object : list)
ret.addChildNode(ImageXMLHelper.toXML(object, languages));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportImagesToXML() failure: " , e);
}
}
public XMLNode exportImagesToXML(String languages[], List list){
XMLNode ret = new XMLNode("Images");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (Image object : list)
ret.addChildNode(ImageXMLHelper.toXML(object, languages));
return ret;
}
public void fetchImage (final String id, Set addedDocuments, JSONArray data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
// This method is not very fast, since it makes an update (eff. save) after each doc.
public void copyMultilingualAttributesInAllImages(String sourceLanguage, String targetLanguage){
throw new AssertionError("Not implemented");
}
public XMLNode exportFileLinksToXML(){
XMLNode ret = new XMLNode("FileLinks");
try{
List list = getFileLinks();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (FileLink object : list)
ret.addChildNode(FileLinkXMLHelper.toXML(object));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportFileLinksToXML() failure: " , e);
}
}
public XMLNode exportFileLinksToXML(List list){
XMLNode ret = new XMLNode("FileLinks");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (FileLink object : list)
ret.addChildNode(FileLinkXMLHelper.toXML(object));
return ret;
}
public XMLNode exportFileLinksToXML(String languages[]){
XMLNode ret = new XMLNode("FileLinks");
try{
List list = getFileLinks();
ret.addAttribute(new XMLAttribute("count", list.size()));
for (FileLink object : list)
ret.addChildNode(FileLinkXMLHelper.toXML(object, languages));
return ret;
}
catch(ASResourceDataServiceException e){;
throw new RuntimeException("exportFileLinksToXML() failure: " , e);
}
}
public XMLNode exportFileLinksToXML(String languages[], List list){
XMLNode ret = new XMLNode("FileLinks");
ret.addAttribute(new XMLAttribute("count", list.size()));
for (FileLink object : list)
ret.addChildNode(FileLinkXMLHelper.toXML(object, languages));
return ret;
}
public void fetchFileLink (final String id, Set addedDocuments, JSONArray data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
public void executeParsingForDocument (final DocumentName documentName, final JSONObject data) throws ASResourceDataServiceException {
throw new UnsupportedOperationException(" not implemented and should not BE!");
}
/**
* Copies all multilingual fields from sourceLanguage to targetLanguage in all data objects (documents, vo) which are part of this module and managed by this service
*/
public void copyMultilingualAttributesInAllObjects(String sourceLanguage, String targetLanguage){
copyMultilingualAttributesInAllTextResources(sourceLanguage, targetLanguage);
copyMultilingualAttributesInAllLocalizationBundles(sourceLanguage, targetLanguage);
copyMultilingualAttributesInAllMailTemplates(sourceLanguage, targetLanguage);
copyMultilingualAttributesInAllImages(sourceLanguage, targetLanguage);
}
/**
* Executes a query on all data objects (documents, vo) which are part of this module and managed by this service
*/
public QueryResult executeQueryOnAllObjects(DocumentQuery query) throws ASResourceDataServiceException {
QueryResult ret = new QueryResult();
ret.add(executeQueryOnTextResources(query).getEntries());
ret.add(executeQueryOnLocalizationBundles(query).getEntries());
ret.add(executeQueryOnMailTemplates(query).getEntries());
ret.add(executeQueryOnImages(query).getEntries());
ret.add(executeQueryOnFileLinks(query).getEntries());
return ret;
} //executeQueryOnAllObjects
@Override public XMLNode exportToXML(){
XMLNode ret = new XMLNode("ASResourceData");
ret.addChildNode(exportTextResourcesToXML());
ret.addChildNode(exportLocalizationBundlesToXML());
ret.addChildNode(exportMailTemplatesToXML());
ret.addChildNode(exportImagesToXML());
ret.addChildNode(exportFileLinksToXML());
return ret;
}
@Override public XMLNode exportToXML(String[] languages){
XMLNode ret = new XMLNode("ASResourceData");
ret.addChildNode(exportTextResourcesToXML(languages));
ret.addChildNode(exportLocalizationBundlesToXML(languages));
ret.addChildNode(exportMailTemplatesToXML(languages));
ret.addChildNode(exportImagesToXML(languages));
ret.addChildNode(exportFileLinksToXML(languages));
return ret;
}
}