com.jaxio.celerio.model.support.EntityListGetters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of celerio-engine Show documentation
Show all versions of celerio-engine Show documentation
Celerio Core Generation Engine
The newest version!
/*
* Copyright 2015 JAXIO http://www.jaxio.com
*
* 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 com.jaxio.celerio.model.support;
import com.jaxio.celerio.model.Attribute;
import com.jaxio.celerio.model.Entity;
import com.jaxio.celerio.model.Relation;
import com.jaxio.celerio.model.Unique;
import com.jaxio.celerio.util.support.ListGetter;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
public class EntityListGetters {
public static ListGetter LOCALIZABLE_TO_DISPLAY_STRING_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
List result = newArrayList();
for (Attribute a : o.printerAttributes()) {
if (a.isLocalizable()) {
result.add(a);
}
}
return result;
}
};
public static ListGetter PRINTER_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.printerAttributes();
}
};
public static ListGetter STRING_PRINTER_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.stringPrinterAttributes();
}
};
public static ListGetter INDEXED_PRINTER_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.indexedPrinterAttributes();
}
};
public static ListGetter ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.getCurrentAttributes();
}
};
public static ListGetter PK_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.getPrimaryKey().getAttributes();
}
};
public static ListGetter CPK_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
if (o.hasCompositePk()) {
return o.getPrimaryKey().getAttributes();
} else {
return emptyList();
}
}
};
public static ListGetter ATTRIBUTES_AND_PK_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
List result = newArrayList();
result.addAll(o.getCurrentAttributes());
if (!o.isRoot()) {
result.addAll(o.getRoot().getPrimaryKey().getAttributes());
}
return result;
}
};
public static ListGetter HIERARCHY_ATTRIBUTES = new ListGetter() {
@Override
public List getList(Entity o) {
return newArrayList(o.getParent());
}
};
public static ListGetter RELATED_ENTITIES = new ListGetter() {
@Override
public List getList(Entity entity) {
ArrayList ret = newArrayList(entity);
for (Relation relation : entity.getRelations().getList()) {
ret.add(relation.getToEntity());
}
return ret;
}
};
public static ListGetter RELATIONS = new ListGetter() {
@Override
public List getList(Entity o) {
return o.getCurrentRelations();
}
};
public static ListGetter UNIQUES = new ListGetter() {
@Override
public List getList(Entity o) {
return o.getCurrentUniques();
}
};
public static ListGetter SEARCH_RESULTS = new ListGetter() {
@Override
public List getList(Entity entity) {
ArrayList ret = newArrayList();
ret.addAll(entity.getSearchResultAttributesManual().getList());
if (ret.size() == 0) {
int left = 6;
for (Attribute attr : entity.getSearchResultAttributesConvention().getList()) {
if (left > 0) {
left--;
ret.add(attr);
}
}
}
return ret;
}
};
}