@Override public Key createKey(String name, String comment, Map<String, Triplet<String, Boolean, Boolean>> translations) { Key key = new Key(); key.setEntityId(name); key.setComment(comment); for (Map.Entry<String, Triplet<String, Boolean, Boolean>> entry : translations.entrySet()) { key.addTranslation(entry.getKey(), entry.getValue().getValue0(), entry.getValue().getValue1(), entry.getValue().getValue2()); } return key; } }
@Override public Key createKey(String name, String comment, boolean outdated) { Key key = new Key(); key.setEntityId(name); key.setComment(comment); key.setOutdated(outdated); return key; }
/** * Returns a sub aggregate key with just the default translation. * * @param defaultLocale source locale * @return Key */ public Key subKey(String defaultLocale) { Key subKey = new Key(); subKey.setComment(description); subKey.setOutdated(outdated); subKey.setEntityId(entityId); Map<String, Translation> subTranslations = new HashMap<String, Translation>(); addTranslation(subTranslations, subKey, defaultLocale); subKey.setTranslations(subTranslations); return subKey; }
/** * Updates a key with the translation in the default language. * * @param representation key representation * @return key representation * @throws URISyntaxException if the URI is not valid. */ @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(I18nPermissions.KEY_WRITE) public Response updateKey(KeyRepresentation representation) throws URISyntaxException { WebAssertions.assertNotNull(representation, THE_KEY_SHOULD_NOT_BE_NULL); WebAssertions.assertNotBlank(representation.getDefaultLocale(), THE_KEY_SHOULD_CONTAINS_A_LOCALE); Key key = loadKeyIfExistsOrFail(); key.setComment(representation.getComment()); key.setOutdated(); // Updates the default translation key.addTranslation(representation.getDefaultLocale(), representation.getTranslation(), representation.isApprox()); keyRepository.update(key); return Response.ok(new URI(uriInfo.getRequestUri() + "/" + keyName)) .entity(keyFinder.findKeyWithName(keyName)).build(); }
/** * Inserts a key with the translation in the default language. * * @param keyRepresentation key representation * @return 201 if the resource is created, 409 if the resource already existed */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(I18nPermissions.KEY_WRITE) public Response createKey(KeyRepresentation keyRepresentation) throws URISyntaxException { WebAssertions.assertNotNull(keyRepresentation, THE_KEY_SHOULD_NOT_BE_NULL); WebAssertions.assertNotBlank(keyRepresentation.getName(), THE_KEY_SHOULD_CONTAINS_A_NAME); WebAssertions.assertNotBlank(keyRepresentation.getDefaultLocale(), THE_KEY_SHOULD_CONTAINS_A_LOCALE); assertKeyDoNotAlreadyExists(keyRepresentation); Key key = factory.createKey(keyRepresentation.getName()); key.setComment(keyRepresentation.getComment()); addDefaultTranslation(keyRepresentation, key); keyRepository.add(key); return Response.created(new URI(uriInfo.getRequestUri() + "/" + key.getId())) .entity(keyFinder.findKeyWithName(key.getId())).build(); }
/** * Returns a sub aggregate key with only two translations. * * @param sourceLocale source locale * @param targetLocale target locale * @return Key */ public Key subKey(String sourceLocale, String targetLocale) { Key subKey = new Key(); subKey.setComment(description); subKey.setOutdated(outdated); subKey.setEntityId(entityId); Map<String, Translation> subTranslations = new HashMap<String, Translation>(); addTranslation(subTranslations, subKey, sourceLocale); addTranslation(subTranslations, subKey, targetLocale); subKey.setTranslations(subTranslations); return subKey; }
@Override protected void doMergeAggregateWithDto(Key targetEntity, KeyDTO sourceDto) { targetEntity.setComment(sourceDto.getComment()); targetEntity.setOutdated(sourceDto.isOutdated()); for (TranslationDTO tln : sourceDto.getTranslations()) { targetEntity.addTranslation(tln.getLocale(), tln.getValue(), tln.isApproximate(), false); } } }
@Override public void mergeDtoIntoAggregate(KeyDTO sourceDto, Key targetAggregate) { targetAggregate.setComment(sourceDto.getComment()); for (TranslationDTO translation : sourceDto.getTranslations()) { targetAggregate.addTranslation(translation.getLocale(), translation.getValue(), translation.isApproximate()); } if (sourceDto.isOutdated()) { targetAggregate.setOutdated(); } for (TranslationDTO translation : sourceDto.getTranslations()) { if (!translation.isOutdated()) { targetAggregate.addTranslation(translation.getLocale(), translation.getValue(), translation.isApproximate()); } } } }