001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.targetplatforms.core.service; 020 021import org.nuxeo.ecm.directory.Session; 022import org.nuxeo.ecm.directory.api.DirectoryService; 023import org.nuxeo.runtime.api.Framework; 024 025/** 026 * Updater in charge of override directory changes. 027 * 028 * @since 5.7.1 029 */ 030public abstract class DirectoryUpdater { 031 032 public static final String DEFAULT_DIR = "targetPlatformOverrides"; 033 034 public static final String SCHEMA = "target_platform_override"; 035 036 public static final String DEPRECATED_PROP = "deprecated"; 037 038 public static final String ENABLED_PROP = "enabled"; 039 040 public static final String RESTRICTED_PROP = "restricted"; 041 042 public static final String TRIAL_PROP = "trial"; 043 044 public static final String DEFAULT_PROP = "default"; 045 046 protected String dirName; 047 048 public DirectoryUpdater(String dirName) { 049 super(); 050 this.dirName = dirName; 051 } 052 053 public abstract void run(DirectoryService service, Session session); 054 055 public void run() { 056 Session session = null; 057 try { 058 // check if entry already exists 059 DirectoryService service = Framework.getService(DirectoryService.class); 060 session = service.open(dirName); 061 run(service, session); 062 } finally { 063 if (session != null) { 064 session.close(); 065 } 066 } 067 } 068 069}