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 java.util.ArrayList;
022import java.util.Collections;
023import java.util.Comparator;
024import java.util.Date;
025import java.util.HashMap;
026import java.util.List;
027import java.util.Locale;
028import java.util.Map;
029
030import org.apache.commons.lang.StringUtils;
031import org.apache.commons.logging.Log;
032import org.apache.commons.logging.LogFactory;
033import org.joda.time.DateTime;
034import org.joda.time.DateTimeZone;
035import org.joda.time.format.DateTimeFormat;
036import org.joda.time.format.DateTimeFormatter;
037import org.nuxeo.ecm.core.api.DocumentModel;
038import org.nuxeo.ecm.directory.BaseSession;
039import org.nuxeo.ecm.directory.DirectoryException;
040import org.nuxeo.ecm.directory.Session;
041import org.nuxeo.ecm.directory.api.DirectoryService;
042import org.nuxeo.runtime.api.Framework;
043import org.nuxeo.runtime.model.ComponentContext;
044import org.nuxeo.runtime.model.ComponentInstance;
045import org.nuxeo.runtime.model.DefaultComponent;
046import org.nuxeo.targetplatforms.api.TargetPackage;
047import org.nuxeo.targetplatforms.api.TargetPackageInfo;
048import org.nuxeo.targetplatforms.api.TargetPlatform;
049import org.nuxeo.targetplatforms.api.TargetPlatformFilter;
050import org.nuxeo.targetplatforms.api.TargetPlatformInfo;
051import org.nuxeo.targetplatforms.api.TargetPlatformInstance;
052import org.nuxeo.targetplatforms.api.impl.TargetPackageImpl;
053import org.nuxeo.targetplatforms.api.impl.TargetPackageInfoImpl;
054import org.nuxeo.targetplatforms.api.impl.TargetPlatformFilterImpl;
055import org.nuxeo.targetplatforms.api.impl.TargetPlatformImpl;
056import org.nuxeo.targetplatforms.api.impl.TargetPlatformInfoImpl;
057import org.nuxeo.targetplatforms.api.impl.TargetPlatformInstanceImpl;
058import org.nuxeo.targetplatforms.api.service.TargetPlatformService;
059import org.nuxeo.targetplatforms.core.descriptors.ServiceConfigurationDescriptor;
060import org.nuxeo.targetplatforms.core.descriptors.TargetPackageDescriptor;
061import org.nuxeo.targetplatforms.core.descriptors.TargetPlatformDescriptor;
062
063/**
064 * {@link TargetPlatformService} implementation relying on runtime extension points.
065 *
066 * @since 5.7.1
067 */
068public class TargetPlatformServiceImpl extends DefaultComponent implements TargetPlatformService {
069
070    private static final Log log = LogFactory.getLog(TargetPlatformServiceImpl.class);
071
072    public static final String XP_CONF = "configuration";
073
074    public static final String XP_PLATFORMS = "platforms";
075
076    public static final String XP_PACKAGES = "packages";
077
078    protected static final DateTimeFormatter dateParser = DateTimeFormat.forPattern("yyyy/MM/dd").withLocale(
079            Locale.ENGLISH).withZone(DateTimeZone.UTC);
080
081    protected ServiceConfigurationRegistry conf;
082
083    protected TargetPlatformRegistry platforms;
084
085    protected TargetPackageRegistry packages;
086
087    // Runtime component API
088
089    @Override
090    public void activate(ComponentContext context) {
091        platforms = new TargetPlatformRegistry();
092        packages = new TargetPackageRegistry();
093        conf = new ServiceConfigurationRegistry();
094    }
095
096    @Override
097    public void deactivate(ComponentContext context) {
098        platforms = null;
099        packages = null;
100        conf = null;
101    }
102
103    @Override
104    public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
105        if (XP_PLATFORMS.equals(extensionPoint)) {
106            TargetPlatformDescriptor desc = (TargetPlatformDescriptor) contribution;
107            log.info(String.format("Register target platform '%s'", desc.getId()));
108            platforms.addContribution(desc);
109        } else if (XP_PACKAGES.equals(extensionPoint)) {
110            TargetPackageDescriptor desc = (TargetPackageDescriptor) contribution;
111            log.info(String.format("Register target package '%s'", desc.getId()));
112            packages.addContribution(desc);
113        } else if (XP_CONF.equals(extensionPoint)) {
114            ServiceConfigurationDescriptor desc = (ServiceConfigurationDescriptor) contribution;
115            log.info(String.format("Register TargetPlatformService configuration"));
116            conf.addContribution(desc);
117        }
118    }
119
120    @Override
121    public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {
122        if (XP_PLATFORMS.equals(extensionPoint)) {
123            TargetPlatformDescriptor desc = (TargetPlatformDescriptor) contribution;
124            log.info(String.format("Unregister target platform '%s'", desc.getId()));
125            platforms.removeContribution(desc);
126        } else if (XP_PACKAGES.equals(extensionPoint)) {
127            TargetPackageDescriptor desc = (TargetPackageDescriptor) contribution;
128            log.info(String.format("Unregister target package '%s'", desc.getId()));
129            packages.removeContribution(desc);
130        } else if (XP_CONF.equals(extensionPoint)) {
131            ServiceConfigurationDescriptor desc = (ServiceConfigurationDescriptor) contribution;
132            log.info(String.format("Unregister TargetPlatformService configuration"));
133            conf.removeContribution(desc);
134        }
135    }
136
137    // Service API
138
139    @Override
140    public TargetPlatform getDefaultTargetPlatform(TargetPlatformFilter filter) {
141        List<TargetPlatform> tps = getAvailableTargetPlatforms(filter);
142        if (tps.isEmpty()) {
143            return null;
144        }
145        TargetPlatform defaultTP = null;
146        for (TargetPlatform tp : tps) {
147            if (tp.isDefault()) {
148                if (!tp.isRestricted()) {
149                    // Return the first default and unrestricted target platform
150                    return tp;
151                }
152                // If the target platform is restricted, we keep it in case no
153                // unrestricted target platform is found
154                if (defaultTP == null) {
155                    defaultTP = tp;
156                }
157            }
158        }
159        return defaultTP;
160    }
161
162    @Override
163    public String getOverrideDirectory() {
164        String res = DirectoryUpdater.DEFAULT_DIR;
165        ServiceConfigurationDescriptor desc = conf.getConfiguration();
166        if (desc == null) {
167            return res;
168        }
169        String id = desc.getOverrideDirectory();
170        if (!StringUtils.isBlank(id)) {
171            res = id;
172        }
173        return res;
174    }
175
176    @Override
177    public TargetPlatform getTargetPlatform(String id) {
178        if (id == null) {
179            return null;
180        }
181        TargetPlatformDescriptor desc = platforms.getTargetPlatform(id);
182        return getTargetPlatform(desc);
183    }
184
185    protected TargetPlatform getTargetPlatform(TargetPlatformDescriptor desc) {
186        if (desc == null) {
187            return null;
188        }
189        String id = desc.getId();
190        TargetPlatformImpl tp = new TargetPlatformImpl(id, desc.getName(), desc.getVersion(), desc.getRefVersion(),
191                desc.getLabel());
192        tp.setDeprecated(desc.isDeprecated());
193        tp.setDescription(desc.getDescription());
194        tp.setDownloadLink(desc.getDownloadLink());
195        tp.setEnabled(desc.isEnabled());
196        tp.setEndOfAvailability(toDate(desc.getEndOfAvailability()));
197        tp.setFastTrack(desc.isFastTrack());
198        tp.setTrial(desc.isTrial());
199        tp.setDefault(desc.isDefault());
200        tp.setParent(getTargetPlatform(desc.getParent()));
201        tp.setRefVersion(desc.getRefVersion());
202        tp.setReleaseDate(toDate(desc.getReleaseDate()));
203        tp.setRestricted(desc.isRestricted());
204        tp.setStatus(desc.getStatus());
205        tp.setTestVersions(desc.getTestVersions());
206        tp.setTypes(desc.getTypes());
207        // resolve available packages
208        tp.setAvailablePackages(getTargetPackages(id));
209
210        // check if there's an override
211        DocumentModel entry = getDirectoryEntry(id);
212        if (entry != null) {
213            Long enabled = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.ENABLED_PROP);
214            if (enabled != null && enabled.intValue() >= 0) {
215                tp.setEnabled(enabled.intValue() == 0 ? false : true);
216            }
217            Long restricted = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.RESTRICTED_PROP);
218            if (restricted != null && restricted.intValue() >= 0) {
219                tp.setRestricted(restricted.intValue() == 0 ? false : true);
220            }
221            Long deprecated = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.DEPRECATED_PROP);
222            if (deprecated != null && deprecated.intValue() >= 0) {
223                tp.setDeprecated(deprecated.intValue() == 0 ? false : true);
224            }
225            Long trial = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.TRIAL_PROP);
226            if (trial != null && trial.intValue() >= 0) {
227                tp.setTrial(trial.intValue() == 0 ? false : true);
228            }
229            Long isDefault = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.DEFAULT_PROP);
230            if (isDefault != null && isDefault.intValue() >= 0) {
231                tp.setDefault(isDefault.intValue() == 0 ? false : true);
232            }
233            tp.setOverridden(true);
234        }
235
236        return tp;
237    }
238
239    /**
240     * Lookup all packages referencing this target platform.
241     */
242    protected Map<String, TargetPackage> getTargetPackages(String targetPlatform) {
243        Map<String, TargetPackage> tps = new HashMap<>();
244        List<TargetPackageDescriptor> pkgs = packages.getTargetPackages(targetPlatform);
245        if (pkgs != null) {
246            for (TargetPackageDescriptor pkg : pkgs) {
247                TargetPackage tp = getTargetPackage(pkg);
248                if (tp != null) {
249                    tps.put(tp.getId(), tp);
250                }
251            }
252        }
253        return tps;
254    }
255
256    protected Map<String, TargetPackageInfo> getTargetPackagesInfo(String targetPlatform) {
257        Map<String, TargetPackageInfo> tps = new HashMap<>();
258        List<TargetPackageDescriptor> pkgs = packages.getTargetPackages(targetPlatform);
259        if (pkgs != null) {
260            for (TargetPackageDescriptor pkg : pkgs) {
261                TargetPackageInfo tp = getTargetPackageInfo(pkg.getId());
262                if (tp != null) {
263                    tps.put(tp.getId(), tp);
264                }
265            }
266        }
267        return tps;
268    }
269
270    protected Date toDate(String date) {
271        if (StringUtils.isBlank(date)) {
272            return null;
273        }
274        DateTime dt = dateParser.parseDateTime(date);
275        return dt.toDate();
276    }
277
278    @Override
279    public TargetPlatformInfo getTargetPlatformInfo(String id) {
280        if (id == null) {
281            return null;
282        }
283        TargetPlatformDescriptor desc = platforms.getTargetPlatform(id);
284        TargetPlatformInfo tpi = getTargetPlatformInfo(desc);
285        return tpi;
286    }
287
288    protected TargetPlatformInfo getTargetPlatformInfo(TargetPlatformDescriptor desc) {
289        if (desc == null) {
290            return null;
291        }
292        String id = desc.getId();
293        TargetPlatformInfoImpl tpi = new TargetPlatformInfoImpl(id, desc.getName(), desc.getVersion(),
294                desc.getRefVersion(), desc.getLabel());
295        tpi.setDescription(desc.getDescription());
296        tpi.setStatus(desc.getStatus());
297        tpi.setEnabled(desc.isEnabled());
298        tpi.setFastTrack(desc.isFastTrack());
299        tpi.setReleaseDate(toDate(desc.getReleaseDate()));
300        tpi.setRestricted(desc.isRestricted());
301        tpi.setEndOfAvailability(toDate(desc.getEndOfAvailability()));
302        tpi.setDownloadLink(desc.getDownloadLink());
303        tpi.setDeprecated(desc.isDeprecated());
304        tpi.setAvailablePackagesInfo(getTargetPackagesInfo(id));
305        tpi.setTypes(desc.getTypes());
306        tpi.setTrial(desc.isTrial());
307        tpi.setDefault(desc.isDefault());
308
309        DocumentModel entry = getDirectoryEntry(id);
310        if (entry != null) {
311            Long enabled = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.ENABLED_PROP);
312            if (enabled != null && enabled.intValue() >= 0) {
313                tpi.setEnabled(enabled.intValue() == 0 ? false : true);
314            }
315            Long restricted = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.RESTRICTED_PROP);
316            if (restricted != null && restricted.intValue() >= 0) {
317                tpi.setRestricted(restricted.intValue() == 0 ? false : true);
318            }
319            Long deprecated = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.DEPRECATED_PROP);
320            if (deprecated != null && deprecated.intValue() >= 0) {
321                tpi.setDeprecated(deprecated.intValue() == 0 ? false : true);
322            }
323            Long trial = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.TRIAL_PROP);
324            if (trial != null && trial.intValue() >= 0) {
325                tpi.setTrial(trial.intValue() == 0 ? false : true);
326            }
327            Long isDefault = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.DEFAULT_PROP);
328            if (isDefault != null && isDefault.intValue() >= 0) {
329                tpi.setDefault(isDefault.intValue() == 0 ? false : true);
330            }
331            tpi.setOverridden(true);
332        }
333
334        return tpi;
335    }
336
337    @Override
338    public TargetPackage getTargetPackage(String id) {
339        if (id == null) {
340            return null;
341        }
342        return getTargetPackage(packages.getTargetPackage(id));
343    }
344
345    @Override
346    public TargetPackageInfo getTargetPackageInfo(String id) {
347        if (id == null) {
348            return null;
349        }
350        TargetPackageDescriptor desc = packages.getTargetPackage(id);
351        TargetPackageInfoImpl tpi = new TargetPackageInfoImpl(desc.getId(), desc.getName(), desc.getVersion(),
352                desc.getRefVersion(), desc.getLabel());
353        tpi.setDescription(desc.getDescription());
354        tpi.setStatus(desc.getStatus());
355        tpi.setEnabled(desc.isEnabled());
356        tpi.setReleaseDate(toDate(desc.getReleaseDate()));
357        tpi.setRestricted(desc.isRestricted());
358        tpi.setEndOfAvailability(toDate(desc.getEndOfAvailability()));
359        tpi.setDownloadLink(desc.getDownloadLink());
360        tpi.setDeprecated(desc.isDeprecated());
361        tpi.setDependencies(desc.getDependencies());
362        return tpi;
363    }
364
365    protected TargetPackage getTargetPackage(TargetPackageDescriptor desc) {
366        if (desc == null) {
367            return null;
368        }
369        TargetPackageImpl tp = new TargetPackageImpl(desc.getId(), desc.getName(), desc.getVersion(),
370                desc.getRefVersion(), desc.getLabel());
371        tp.setDependencies(desc.getDependencies());
372        tp.setDeprecated(desc.isDeprecated());
373        tp.setDescription(desc.getDescription());
374        tp.setDownloadLink(desc.getDownloadLink());
375        tp.setEnabled(desc.isEnabled());
376        tp.setEndOfAvailability(toDate(desc.getEndOfAvailability()));
377        tp.setParent(getTargetPackage(desc.getParent()));
378        tp.setRefVersion(desc.getRefVersion());
379        tp.setReleaseDate(toDate(desc.getReleaseDate()));
380        tp.setRestricted(desc.isRestricted());
381        tp.setStatus(desc.getStatus());
382        tp.setTypes(desc.getTypes());
383        return tp;
384    }
385
386    @Override
387    public TargetPlatformInstance getTargetPlatformInstance(String id, List<String> packages) {
388        if (id == null) {
389            return null;
390        }
391
392        TargetPlatformInstanceImpl tpi = createTargetPlatformInstanceFromId(id);
393
394        if (packages != null) {
395            for (String pkg : packages) {
396                TargetPackage tpkg = getTargetPackage(pkg);
397                if (tpkg != null) {
398                    tpi.addEnabledPackage(tpkg);
399                } else {
400                    log.warn(String.format("Referenced target package '%s' not found.", pkg));
401                }
402            }
403        }
404
405        return tpi;
406    }
407
408    @Override
409    public List<TargetPlatform> getAvailableTargetPlatforms(TargetPlatformFilter filter) {
410        List<TargetPlatform> tps = new ArrayList<>();
411        for (TargetPlatformDescriptor desc : platforms.getTargetPlatforms()) {
412            TargetPlatform tp = getTargetPlatform(desc);
413            if (tp == null) {
414                continue;
415            }
416            if (filter != null && !filter.accepts(tp)) {
417                continue;
418            }
419            tps.add(tp);
420        }
421        // always sort for a deterministic result
422        Collections.sort(tps, new Comparator<TargetPlatform>() {
423            @Override
424            public int compare(TargetPlatform arg0, TargetPlatform arg1) {
425                return arg0.getId().compareTo(arg1.getId());
426            }
427        });
428        return tps;
429    }
430
431    @Override
432    public List<TargetPlatformInfo> getAvailableTargetPlatformsInfo(TargetPlatformFilter filter) {
433        List<TargetPlatformInfo> tps = new ArrayList<>();
434        for (TargetPlatformDescriptor desc : platforms.getTargetPlatforms()) {
435            TargetPlatformInfo tp = getTargetPlatformInfo(desc);
436            if (tp == null) {
437                continue;
438            }
439            if (filter != null && !filter.accepts(tp)) {
440                continue;
441            }
442            tps.add(tp);
443        }
444        Collections.sort(tps, new Comparator<TargetPlatformInfo>() {
445            @Override
446            public int compare(TargetPlatformInfo arg0, TargetPlatformInfo arg1) {
447                return arg0.getId().compareTo(arg1.getId());
448            }
449        });
450        return tps;
451    }
452
453    @Override
454    public void deprecateTargetPlatform(boolean deprecate, final String id) {
455        Integer val = deprecate ? Integer.valueOf(1) : Integer.valueOf(0);
456        updateOrCreateEntry(id, DirectoryUpdater.DEPRECATED_PROP, val);
457    }
458
459    @Override
460    public void enableTargetPlatform(boolean enable, final String id) {
461        Integer val = enable ? Integer.valueOf(1) : Integer.valueOf(0);
462        updateOrCreateEntry(id, DirectoryUpdater.ENABLED_PROP, val);
463    }
464
465    @Override
466    public void restrictTargetPlatform(boolean restrict, final String id) {
467        Integer val = restrict ? Integer.valueOf(1) : Integer.valueOf(0);
468        updateOrCreateEntry(id, DirectoryUpdater.RESTRICTED_PROP, val);
469    }
470
471    @Override
472    public void setTrialTargetPlatform(boolean trial, final String id) {
473        Integer val = trial ? Integer.valueOf(1) : Integer.valueOf(0);
474        updateOrCreateEntry(id, DirectoryUpdater.TRIAL_PROP, val);
475    }
476
477    @Override
478    public void setDefaultTargetPlatform(boolean isDefault, final String id) {
479        Integer val = isDefault ? Integer.valueOf(1) : Integer.valueOf(0);
480        updateOrCreateEntry(id, DirectoryUpdater.DEFAULT_PROP, val);
481    }
482
483    @Override
484    public void restoreTargetPlatform(final String id) {
485        new DirectoryUpdater(getOverrideDirectory()) {
486            @Override
487            public void run(DirectoryService service, Session session) {
488                session.deleteEntry(id);
489            }
490        }.run();
491    }
492
493    @Override
494    public void restoreAllTargetPlatforms() {
495        new DirectoryUpdater(getOverrideDirectory()) {
496            @Override
497            public void run(DirectoryService service, Session session) {
498                for (DocumentModel entry : session.getEntries()) {
499                    session.deleteEntry(entry.getId());
500                }
501            }
502        }.run();
503    }
504
505    protected void updateOrCreateEntry(final String id, final String prop, final Integer value) {
506        new DirectoryUpdater(getOverrideDirectory()) {
507            @Override
508            public void run(DirectoryService service, Session session) {
509                DocumentModel doc = session.getEntry(id);
510                if (doc != null) {
511                    doc.setProperty(DirectoryUpdater.SCHEMA, prop, value);
512                    session.updateEntry(doc);
513                } else {
514                    DocumentModel entry = BaseSession.createEntryModel(null, DirectoryUpdater.SCHEMA, null, null);
515                    entry.setProperty(DirectoryUpdater.SCHEMA, prop, value);
516                    entry.setProperty(DirectoryUpdater.SCHEMA, "id", id);
517                    session.createEntry(entry);
518                }
519            }
520        }.run();
521    }
522
523    protected DocumentModel getDirectoryEntry(String id) {
524        Session dirSession = null;
525        try {
526            // check if entry already exists
527            DirectoryService dirService = Framework.getService(DirectoryService.class);
528            String dirName = getOverrideDirectory();
529            dirSession = dirService.open(dirName);
530            return dirSession.getEntry(id);
531        } finally {
532            if (dirSession != null) {
533                dirSession.close();
534            }
535        }
536    }
537
538    @Override
539    public TargetPlatformInstance getDefaultTargetPlatformInstance(boolean restricted) {
540        TargetPlatformInstance tpi = null;
541        TargetPlatformFilterImpl filter = new TargetPlatformFilterImpl();
542        filter.setFilterRestricted(restricted);
543        TargetPlatform defaultTP = getDefaultTargetPlatform(filter);
544        if (defaultTP != null) {
545            tpi = createTargetPlatformInstanceFromId(defaultTP.getId());
546        }
547
548        return tpi;
549    }
550
551    /**
552     * Create a TargetPlatformInstance given an id.
553     *
554     * @since 5.9.3-NXP-15602
555     */
556    protected TargetPlatformInstanceImpl createTargetPlatformInstanceFromId(String id) {
557        TargetPlatformDescriptor desc = platforms.getTargetPlatform(id);
558        if (desc == null) {
559            return null;
560        }
561        TargetPlatformInstanceImpl tpi = new TargetPlatformInstanceImpl(id, desc.getName(), desc.getVersion(),
562                desc.getRefVersion(), desc.getLabel());
563        tpi.setDeprecated(desc.isDeprecated());
564        tpi.setDescription(desc.getDescription());
565        tpi.setDownloadLink(desc.getDownloadLink());
566        tpi.setEnabled(desc.isEnabled());
567        tpi.setEndOfAvailability(toDate(desc.getEndOfAvailability()));
568        tpi.setFastTrack(desc.isFastTrack());
569        tpi.setParent(getTargetPlatform(desc.getParent()));
570        tpi.setRefVersion(desc.getRefVersion());
571        tpi.setReleaseDate(toDate(desc.getReleaseDate()));
572        tpi.setRestricted(desc.isRestricted());
573        tpi.setStatus(desc.getStatus());
574        tpi.setTypes(desc.getTypes());
575
576        DocumentModel entry = getDirectoryEntry(id);
577        if (entry != null) {
578            Long enabled = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.ENABLED_PROP);
579            if (enabled != null && enabled.intValue() >= 0) {
580                tpi.setEnabled(enabled.intValue() == 0 ? false : true);
581            }
582            Long restricted = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.RESTRICTED_PROP);
583            if (restricted != null && restricted.intValue() >= 0) {
584                tpi.setRestricted(restricted.intValue() == 0 ? false : true);
585            }
586            Long deprecated = (Long) entry.getProperty(DirectoryUpdater.SCHEMA, DirectoryUpdater.DEPRECATED_PROP);
587            if (deprecated != null && deprecated.intValue() >= 0) {
588                tpi.setDeprecated(deprecated.intValue() == 0 ? false : true);
589            }
590            tpi.setOverridden(true);
591        }
592
593        return tpi;
594    }
595}