com.xlrit.gears.plugin.msgraph.IdentitySyncService Maven / Gradle / Ivy
package com.xlrit.gears.plugin.msgraph;
import com.xlrit.gears.base.schedule.ScheduledRunnable;
import com.xlrit.gears.base.repository.RoleRepository;
import com.xlrit.gears.base.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class IdentitySyncService extends ScheduledRunnable {
private final String cronExpression;
private final Sync sync;
private final SyncHandler handler;
@Autowired
public IdentitySyncService(SyncProperties properties, RoleRepository roles, UserRepository users) {
this.cronExpression = properties.getCron();
if (properties.isEnabled()) {
this.sync = new Sync(properties);
this.handler = new SyncHandlerImpl(properties.getGroupMapping(), roles, users);
}
else {
this.sync = null;
this.handler = null;
}
}
@Override
protected boolean isEnabled() {
return this.sync != null && this.handler != null;
}
@Override
protected String getCronExpression() {
return cronExpression;
}
@Override
protected void runScheduled() {
this.sync.run(this.handler);
}
}