-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from entur/branding
Branding
- Loading branch information
Showing
22 changed files
with
635 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/no/entur/uttu/export/netex/producer/common/BrandingProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package no.entur.uttu.export.netex.producer.common; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import no.entur.uttu.export.netex.NetexExportContext; | ||
import org.rutebanken.netex.model.Branding; | ||
import org.rutebanken.netex.model.MultilingualString; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class BrandingProducer { | ||
|
||
public List<Branding> produce(NetexExportContext context) { | ||
return context.brandings | ||
.stream() | ||
.map(branding -> | ||
new Branding() | ||
.withId(branding.getNetexId()) | ||
.withVersion("1") | ||
.withName(new MultilingualString().withValue(branding.getName())) | ||
.withShortName( | ||
branding.getShortName() != null | ||
? new MultilingualString().withValue(branding.getShortName()) | ||
: null | ||
) | ||
.withDescription( | ||
branding.getDescription() != null | ||
? new MultilingualString().withValue(branding.getDescription()) | ||
: null | ||
) | ||
.withUrl(branding.getUrl()) | ||
.withImage(branding.getImageUrl()) | ||
) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/no/entur/uttu/graphql/fetchers/BrandingUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package no.entur.uttu.graphql.fetchers; | ||
|
||
import graphql.schema.DataFetchingEnvironment; | ||
import no.entur.uttu.error.codederror.EntityHasReferencesCodedError; | ||
import no.entur.uttu.graphql.mappers.AbstractProviderEntityMapper; | ||
import no.entur.uttu.model.Branding; | ||
import no.entur.uttu.repository.FixedLineRepository; | ||
import no.entur.uttu.repository.FlexibleLineRepository; | ||
import no.entur.uttu.repository.generic.ProviderEntityRepository; | ||
import no.entur.uttu.util.Preconditions; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service("brandingUpdater") | ||
@Transactional | ||
public class BrandingUpdater extends AbstractProviderEntityUpdater<Branding> { | ||
|
||
private final FixedLineRepository fixedLineRepository; | ||
private final FlexibleLineRepository flexibleLineRepository; | ||
|
||
public BrandingUpdater( | ||
AbstractProviderEntityMapper<Branding> mapper, | ||
ProviderEntityRepository<Branding> repository, | ||
FixedLineRepository fixedLineRepository, | ||
FlexibleLineRepository flexibleLineRepository | ||
) { | ||
super(mapper, repository); | ||
this.fixedLineRepository = fixedLineRepository; | ||
this.flexibleLineRepository = flexibleLineRepository; | ||
} | ||
|
||
@Override | ||
protected Branding deleteEntity(DataFetchingEnvironment env) { | ||
return super.deleteEntity(env); | ||
} | ||
|
||
@Override | ||
protected void verifyDeleteAllowed(String id) { | ||
var branding = repository.getOne(id); | ||
if (branding != null) { | ||
long noOfLines = | ||
fixedLineRepository.countByBranding(branding) + | ||
flexibleLineRepository.countByBranding(branding); | ||
Preconditions.checkArgument( | ||
noOfLines == 0, | ||
EntityHasReferencesCodedError.fromNumberOfReferences((int) noOfLines), | ||
"%s cannot be deleted as it is referenced by %s line(s)", | ||
branding.identity(), | ||
noOfLines | ||
); | ||
} | ||
super.verifyDeleteAllowed(id); | ||
} | ||
} |
Oops, something went wrong.