+
+ protected class ContentToIsLockedField implements EntityAdapterDefinition.CalculatedField {
+ private ModuleContent contentModule;
+
+ public ContentToIsLockedField() {
+ contentModule = new ModuleContent();
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return new Boolean(contentModule.queryArticleLock(anEntityAdapter.getEntity().getId())!=null);
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+ protected class ContentIsOriginalField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+
+ //ML: add check on article type
+ boolean result = (anEntityAdapter.get("parent")==null);
+
+ return new Boolean(result);
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToOriginalField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ if (anEntityAdapter.get("parent")!=null)
+ return anEntityAdapter.get("parent");
+ return anEntityAdapter;
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationsField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ try {
+ return anEntityAdapter.getRelation(
+ "is_published='t' and to_content="+anEntityAdapter.get("id"),
+ "id",
+ "content" );
+ }
+ catch (Throwable t) {
+ throw new RuntimeException(t.getMessage());
+ }
+ }
+ }
+
+ protected class ContentToLanguageNameField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ String result = "";
+ EntityAdapter language = (EntityAdapter) anEntityAdapter.get("language");
+ if (language != null) {
+ if (language.get("code").equals("ot")) {
+ result = ((String) anEntityAdapter.get("subtitle")).trim();
+ if (result == null || result.equals(""))
+ result = (String) language.get("name");
+ } else {
+ result = (String) language.get("name");
+ }
+ }
+
+ return result;
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationFunction implements Generator.Function {
+ private EntityAdapter target;
+ private String targetId;
+ private String targetLanguageId;
+
+ public ContentToTranslationFunction(EntityAdapter aTarget) {
+ target = aTarget;
+ targetId = (String) target.get("id");
+ targetLanguageId = (String) target.get("to_language");
+ }
+
+ public Object perform(List aParameters) throws GeneratorExc, GeneratorFailure {
+ if (aParameters.size()!=1 || !(aParameters.get(0) instanceof String))
+ throw new GeneratorExc("1 string parameter expected");
+
+ try {
+ String language = (String) aParameters.get(0);
+ String languageId = languageModule.languageIdForCode(language);
+ Object result = null;
+
+ if (languageId != null && !targetLanguageId.equals(languageId)) {
+ result = target.getToOneRelation(
+ "is_published='t' and to_content=" + targetId + " and to_language='" + JDBCStringRoutines.escapeStringLiteral(languageId) + "'",
+ "id", "content");
+ }
+
+ if (result == null)
+ result = target;
+
+ return result;
+ }
+ catch (Throwable t) {
+ t.printStackTrace(System.out);
+ throw new GeneratorFailure(t);
+ }
+ }
+ }
+
+ protected class ContentToTranslationField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) throws MirLocalizerFailure {
+ try {
+ return new ContentToTranslationFunction((EntityAdapter) anEntityAdapter.get("to_original"));
+ }
+ catch (Throwable t) {
+ throw new MirLocalizerFailure(t);
+ }
+ }
+ }
+
+ protected static class CommentStatusCountField implements EntityAdapterDefinition.CalculatedField {
+ public Object getValue(EntityAdapter anEntityAdapter) {
+ return new CommentStatusCountField2(anEntityAdapter);
+ }
+ }
+
+ public static class CommentStatusCountField2 {
+ private final EntityAdapter comment;
+ private final ModuleCommentStatus mcs = new ModuleCommentStatus();
+
+ CommentStatusCountField2(EntityAdapter anEntityAdapter) {
+ comment = anEntityAdapter;
+ }
+
+ public String get(String aCommentStatus) {
+ try {
+ return Integer.toString(
+ DatabaseComment.getInstance().getSize(
+ "to_media=" + comment.get("id") + " and is_published='1' and to_comment_status = " +
+ mcs.commentStatusIdForName(aCommentStatus)));
+ }
+ catch (Exception e) {
+ return "0";
+ }
+ }
+ }