fr.ird.observe.spi.context.EmptyChildrenDataReferenceSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-service Show documentation
Show all versions of toolkit-service Show documentation
ObServe Toolkit Service module
The newest version!
package fr.ird.observe.spi.context;
/*-
* #%L
* ObServe Toolkit :: Service
* %%
* Copyright (C) 2017 - 2021 Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
import fr.ird.observe.dto.reference.LazyDataDtoReferenceSet;
import fr.ird.observe.dto.reference.UpdatedDataDtoReferenceSet;
import fr.ird.observe.services.service.data.OpenableService;
import fr.ird.observe.spi.ServicesProvider;
import fr.ird.observe.spi.decoration.DecoratorService;
import java.util.Comparator;
import java.util.Objects;
/**
* Created on 14/01/2021.
*
* @author Tony Chemit - [email protected]
* @since 8.0.3
*/
public class EmptyChildrenDataReferenceSet extends LazyDataDtoReferenceSet {
private final String parentId;
private final OpenableDtoServiceContext, R> spi;
private final ServicesProvider servicesProvider;
private final DecoratorService decoratorService;
EmptyChildrenDataReferenceSet(String parentId, int initialCount, OpenableDtoServiceContext, R> spi, ServicesProvider servicesProvider, DecoratorService decoratorService) {
super(spi.getReferenceType(), initialCount);
this.parentId = Objects.requireNonNull(parentId);
this.spi = Objects.requireNonNull(spi);
this.servicesProvider = Objects.requireNonNull(servicesProvider);
this.decoratorService = Objects.requireNonNull(decoratorService);
}
@Override
public Comparator getReferenceComparator() {
return spi.getReferenceComparator();
}
@Override
protected DataDtoReferenceSet createDelegate() {
DataDtoReferenceSet previousResult = getDelegate();
DataDtoReferenceSet result;
OpenableService service = servicesProvider.getService(OpenableService.class);
if (previousResult == null) {
// first time load all data
result = service.getChildren(spi.getDtoType(), parentId);
} else {
// ask an update of data
UpdatedDataDtoReferenceSet updateResult = service.getChildrenUpdate(spi.getDtoType(), parentId, previousResult.getLastUpdate());
// merge it with previous data
result = updateResult.mergeTo(previousResult);
}
result.sort(spi.getReferenceComparator());
decoratorService.installDecorator(result);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy