Commit 78d9391c authored by Nugraha, Sigit's avatar Nugraha, Sigit
Browse files

Update multi-language for Question and Statement

parent 72825006
Pipeline #15293 passed with stage
in 2 minutes and 16 seconds
package org.gesis.stardat;
import java.util.Collections;
import java.util.Locale;
import org.gesis.stardat.helper.CollaborationUserContext;
import org.gesis.stardat.service.CachingDDIFlatDBRestClient;
import org.gesis.stardat.service.ElementManager;
......@@ -27,7 +24,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.stardat.management.client.ManagementRestClient;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
......@@ -36,6 +32,9 @@ import org.thymeleaf.templateresolver.StringTemplateResolver;
import org.vaadin.spring.i18n.MessageProvider;
import org.vaadin.spring.i18n.ResourceBundleMessageProvider;
import java.util.Collections;
import java.util.Locale;
@SpringBootApplication( exclude = { SecurityAutoConfiguration.class, ThymeleafAutoConfiguration.class } )
@EnableCaching
@ComponentScan( basePackages = { "org.gesis", "org.gesis.stardat", "org.stardat.management" } )
......@@ -58,7 +57,6 @@ public class DDIEditorApplication
public static void main( String[] args )
{
SpringApplication.run( DDIEditorApplication.class, args );
}
@Bean
......@@ -67,13 +65,6 @@ public class DDIEditorApplication
return new ElementManager( new CachingDDIFlatDBRestClient( ddiFlatDBEndPoint ) );
}
@Bean
public ManagementRestClient managementRestClient()
{
logger.debug( "ManagementURI: " + managementURI );
return new ManagementRestClient( managementURI );
}
@Bean
public CacheManager cacheManager()
{
......
package org.gesis.stardat.domain.enumeration;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
/**
* The Language enumeration.
*/
......@@ -20,7 +20,7 @@ public enum Language {
ENGLISH_MACEDONIAN( "en", "en-MK" , "English (en)", "English", "datacatalogue-en-ddi32", "gesisquestionnaire-en-32"),
ESTONIAN( "et", "et" , "Estonian (et)", "Estonian", "datacatalogue-ddi32", "gesisquestionnaire32"),
FINNISH( "fi", "fi" , "Finnish (fi)", "Finnish", "datacatalogue-ddi32", "gesisquestionnaire32"),
FRENCH( "fr", "fr" , "French (fr)", "French", "datacatalogue-ddi32", "gesisquestionnaire32"),
FRENCH( "fr", "fr-FR" , "French (fr)", "French", "datacatalogue-ddi32", "gesisquestionnaire32"),
GERMAN( "de", "de-DE" , "German (de)", "German", "datacatalogue-ddi32", "gesisquestionnaire32"),
GREEK( "el", "el" , "Greek (el)", "Greek", "datacatalogue-ddi32", "gesisquestionnaire32"),
HUNGARIAN( "hu", "hu" , "Hungarian (hu)", "Hungarian", "datacatalogue-ddi32", "gesisquestionnaire32"),
......
package org.gesis.stardat.management;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.gesis.stardat.management.dto.StardatObjectDTO;
import org.gesis.stardat.management.dto.StardatObjectTagDTO;
import org.gesis.stardat.management.dto.TagDTO;
import org.gesis.stardat.management.enumeration.StardatObjectStatus;
import org.gesis.stardat.management.enumeration.StardatObjectType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.stardat.management.client.ManagementRestClient;
import org.stardat.management.client.Status;
import org.stardat.management.client.Tag;
@Service
public class ManagementMigrationService
{
private final Logger log = LoggerFactory.getLogger( ManagementMigrationService.class );
private RestTemplate restTemplate;
@Value( "${managemententities.server.uri}" )
String managementEntitiesURI;
@Value( "${stardat.management.uri}" )
String stardatManagementUri;
private final ManagementService managementService;
private final StardatObjectService stardatObjectService;
private final ManagementRestClient managementRestClient;
public ManagementMigrationService( ManagementService managementService, StardatObjectService stardatObjectService,
ManagementRestClient managementRestClient )
{
this.managementService = managementService;
this.stardatObjectService = stardatObjectService;
this.managementRestClient = managementRestClient;
this.restTemplate = new RestTemplate();
}
public void doMigration()
{
// do status migration
ResponseEntity<List<Status>> statusResults = restTemplate.exchange( managementEntitiesURI + "status",
HttpMethod.GET, null, new ParameterizedTypeReference<List<Status>>()
{
} );
// tag migration
List<Tag> userTagList = managementRestClient.getTagListForUser( "admin" );
List<Status> statuses = statusResults.getBody();
for ( Status status : statuses )
{
StardatObjectDTO stardatObjectDTO = new StardatObjectDTO();
stardatObjectDTO.setReferredObjectId( status.getStatusObjectId() );
stardatObjectDTO.setStatus( StardatObjectStatus.getEnumById( status.getStatus() ) );
stardatObjectDTO.setNoOfRating( 0 );
stardatObjectDTO.setCalculatedRating( 0.0 );
stardatObjectDTO.setType( StardatObjectType.QUESTION );
Optional<StardatObjectDTO> byReferredObjectId = stardatObjectService
.findByReferredObjectId( status.getStatusObjectId() );
if ( !byReferredObjectId.isPresent() )
{
log.debug( "Saving: ReferredObject {} status {}", stardatObjectDTO.getReferredObjectId(),
stardatObjectDTO.getStatus() );
stardatObjectDTO = stardatObjectService.save( stardatObjectDTO );
}
// persistTags
StardatObjectDTO finalStardatObjectDTO = stardatObjectDTO;
List<Tag> tags = userTagList.stream()
.filter( t -> t.getTaggedObjectId().equals( finalStardatObjectDTO.getReferredObjectId() ) )
.collect( Collectors.toList() );
// convert tag into Tag and StardatObjectTag and Tag
for ( Tag tag : tags )
{
TagDTO tagDTO = null;
Optional<TagDTO> tagOpt = managementService.getTagService().findByName( tag.getTag().toLowerCase() );
if ( tagOpt.isPresent() )
tagDTO = tagOpt.get();
else
{
// create a new tag if not exist
tagDTO = new TagDTO();
tagDTO.setName( tag.getTag().toLowerCase() );
tagDTO = managementService.getTagService().save( tagDTO );
}
// save tag object if not exist
StardatObjectTagDTO stardatObjectTagDTO = null;
Optional<StardatObjectTagDTO> sotDtoOpt = managementService.getStardatObjectTagService()
.findByTagIdAndUserIdAndReferredObjectId( tagDTO.getId(), 1L,
stardatObjectDTO.getReferredObjectId() );
if ( sotDtoOpt.isPresent() )
continue;
stardatObjectTagDTO = new StardatObjectTagDTO();
stardatObjectTagDTO.setStardatObjectId( stardatObjectDTO.getId() );
stardatObjectTagDTO.setDate( LocalDate.now() );
stardatObjectTagDTO.setTagId( tagDTO.getId() );
stardatObjectTagDTO.setUserId( 1L );
stardatObjectTagDTO.setTagDTO( tagDTO );
stardatObjectTagDTO = managementService.getStardatObjectTagService().save( stardatObjectTagDTO );
}
}
}
}
......@@ -29,7 +29,7 @@ public class ConfigurationService {
@Value("${qmd.mail.sender}")
private String qmdMailSender;
@Value("${app.language.source.iso3.enable}")
@Value("${app.language.iso3.enable}")
private String enableLanguageByIso3;
@Value("${group.language.default}")
......@@ -37,6 +37,12 @@ public class ConfigurationService {
@Value("${group.dialectDefinition.default}")
String groupDialectDefinitionDefault;
@Value("${study.language.default}")
String studyLanguageDefault;
@Value("${study.dialectDefinition.default}")
String studyDialectDefinitionDefault;
public String getServerContextPath() {
return serverContextPath;
......@@ -78,7 +84,7 @@ public class ConfigurationService {
this.qmdMailSender = qmdMailSender;
}
public List<Language> getSourceLanguagesByIso3(){
public List<Language> getEnableLanguagesByIso3(){
List<Language> languages = new ArrayList<>();
for (String iso3 : enableLanguageByIso3.split(",")) {
final Language language = Language.getByIso3(iso3);
......@@ -96,13 +102,27 @@ public class ConfigurationService {
Language language = null;
try {
language = Language.getByIso3(groupLanguageDefault);
} catch (Exception e) {
}
} catch (Exception e) {}
return language;
}
public String getGroupDialectDefinitionDefault() {
return groupDialectDefinitionDefault;
}
public String getStudyLanguageDefault() {
return studyLanguageDefault;
}
public Language getStudyLanguageEnumDefault() {
Language language = null;
try {
language = Language.getByIso3(studyLanguageDefault);
} catch (Exception e) {}
return language;
}
public String getStudyDialectDefinitionDefault() {
return studyDialectDefinitionDefault;
}
}
......@@ -631,16 +631,16 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
}
if ( this.availableQuestionStatuses.contains( currentSelectedQuestionRow.getStatus() ) )
{
if ( currentQuestionnaireElement.getType().equals( DDIElement.STATEMENT ) )
if ( currentSelectedQuestionRow.getObject().getType().equals( DDIElement.STATEMENT ) )
{
UI.getCurrent().addWindow(
new StatementWindow( (Statement) currentQuestionnaireElement, getRestClient(), this ) );
new StatementWindow( (Statement) currentSelectedQuestionRow.getObject(), getRestClient(), this ) );
}
else
{
setRunFilltreeAfterEdit( false );
UI.getCurrent().addWindow(
new QuestionWindow( (QuestionConstruct) currentQuestionnaireElement,
new QuestionWindow( (QuestionConstruct) currentSelectedQuestionRow.getObject(),
currentSelectedQuestionRow.getSequence(),
codeLists, interviewerInstructions, concepts, this,
cacheService, entityService, eventBus ) );
......@@ -658,8 +658,8 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
{
UI.getCurrent().addWindow(
new StatementTranslateWindow( (Statement) currentQuestionnaireElement, getRestClient(),
this ) );
new StatementTranslateWindow( (Statement) currentQuestionnaireElement,
this, configurationService ) );
}
else
{
......@@ -668,7 +668,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
new QuestionTranslateWindow( (QuestionConstruct) currentQuestionnaireElement,
currentSelectedQuestionRow.getSequence(),
codeLists, interviewerInstructions, concepts, this,
cacheService, entityService, eventBus ) );
cacheService, entityService, eventBus, configurationService ) );
}
}
......@@ -806,9 +806,9 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
itemClickListenerRegistration = questionGrid.addItemClickListener( listener ->
{
currentQuestionnaireElement = currentSelectedQuestionRow.getObject();
if ( listener.getItem() != null && listener.getMouseEventDetails().isDoubleClick() )
{
currentQuestionnaireElement = currentSelectedQuestionRow.getObject();
editCurrentlySelectedQuestionOrStatement();
}
} );
......@@ -1119,7 +1119,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
ArrayList<String> availableLanguages = null;
if ( item.getObject().getType().equals( DDIElement.STATEMENT ) )
{
if( SOURCE_LANG.contains( "en" ))
if( configurationService.getEnableLanguagesByIso3().size() < 2)
translateQuestion.setVisible( false );
availableLanguages = ((Statement) item.getObject()).getAvailableLanguages();
}
......@@ -1127,7 +1127,8 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
{
final QuestionConstruct questionConstruct = (QuestionConstruct) item.getObject();
SOURCE_LANG = questionConstruct.getQuestion().getLanguage();
if( SOURCE_LANG.contains( "en" ))
// must be visible if
if( configurationService.getEnableLanguagesByIso3().size() < 2)
translateQuestion.setVisible( false );
availableLanguages = questionConstruct.getQuestion().getAvailableLanguages();
}
......@@ -1138,9 +1139,11 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
questionPrev.add( mCssButtonLayout, htmlPrev );
questionsPreview.add( questionPrev );
if( availableLanguages.size() > 1 ) {
String finalSOURCE_LANG = SOURCE_LANG;
availableLanguages.forEach(lang ->
{
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
final MButton langButton = new MButton(Language.getIso3Map().get(lang).getIso().toUpperCase())
.withDescription(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent ->
{
......@@ -1161,15 +1164,14 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
((DDIEditor) UI.getCurrent()).getCurrentGroup(),
lang, mode));
}
}));
});
mCssButtonLayout.add( langButton );
if ( lang.equals(finalSOURCE_LANG)) {
langButton.addStyleNames( "pressed" );
}
});
}
if ( mCssButtonLayout.getComponentCount() > 0 )
{
Component component = mCssButtonLayout.getComponent( 0 );
if ( component != null )
component.addStyleNames( "pressed" );
}
if ( item.getObject().getType().equals( DDIElement.STATEMENT ) )
{
mode = "statement";
......
package org.gesis.stardat.ui;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.data.provider.TreeDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.renderers.ComponentRenderer;
import com.vaadin.ui.themes.ValoTheme;
import org.gesis.stardat.DDIEditor;
import org.gesis.stardat.ddiflatdb.client.DDIStore;
import org.gesis.stardat.entity.*;
......@@ -33,7 +34,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.stardat.management.client.ManagementRestClient;
import org.stardat.management.client.Tag;
import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
......@@ -42,19 +42,16 @@ import org.vaadin.viritin.grid.MGrid;
import org.vaadin.viritin.layouts.MVerticalLayout;
import org.vaadin.viritin.navigator.MView;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.data.provider.TreeDataProvider;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.spring.annotation.ViewScope;
import com.vaadin.ui.*;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.renderers.ComponentRenderer;
import com.vaadin.ui.themes.ValoTheme;
import javax.annotation.PostConstruct;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ViewScope
@SpringView( name = QuestionnaireOverView.VIEW_NAME )
......@@ -69,9 +66,6 @@ public class QuestionnaireOverView extends MVerticalLayout implements MView, Tra
private Logger logger = LoggerFactory.getLogger( QuestionnaireOverView.class );
@Autowired
ManagementRestClient tagsRestClient;
public static final String VIEW_NAME = "QuestionnaireOverview";
public static final String ID = "id";
......
......@@ -69,7 +69,7 @@ public class GroupForm extends FormLayout implements Translatable {
languageComboBox.setEmptySelectionAllowed( false );
languageComboBox.setCaption(I18N.get("language.source"));
languageComboBox.setItemCaptionGenerator( Language::getFormatted );
final List<Language> languages = configurationService.getSourceLanguagesByIso3();
final List<Language> languages = configurationService.getEnableLanguagesByIso3();
if( !languages.isEmpty() ) {
languageComboBox.setItems(languages);
languageComboBox.setSelectedItem(languages.get(0));
......
......@@ -112,7 +112,8 @@ public class InterviewerInstructionForm extends MVerticalLayout
mCssButtonLayout.removeAllComponents();
if( availableLanguages.size() > 1 ) {
availableLanguages.forEach(lang -> {
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getIso().toUpperCase())
.withDescription(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent -> {
mCssButtonLayout.forEach(c -> c.removeStyleName("pressed"));
......
package org.gesis.stardat.ui.view.migration;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.spring.annotation.UIScope;
import org.gesis.stardat.management.ManagementMigrationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vaadin.viritin.button.MButton;
import org.vaadin.viritin.layouts.MVerticalLayout;
import org.vaadin.viritin.navigator.MView;
import javax.annotation.PostConstruct;
@UIScope
@SpringView(name = ManagementMigrationView.VIEW_NAME)
public class ManagementMigrationView extends MVerticalLayout implements MView {
private static Logger log = LoggerFactory.getLogger(ManagementMigrationView.class);
private static final long serialVersionUID = 7507113469527084448L;
public static final String VIEW_NAME = "management-migration";
private final transient ManagementMigrationService managementMigrationService;
private MButton managementMigrationButton = new MButton("Do Migration for Management",event -> doMigration());
public ManagementMigrationView(ManagementMigrationService managementMigrationService) {
this.managementMigrationService = managementMigrationService;
}
@PostConstruct
public void init() {
this.withUndefinedHeight().add( managementMigrationButton );
}
private void doMigration() {
managementMigrationService.doMigration();
}
public void enter(ViewChangeListener.ViewChangeEvent event){
}
@Override
public boolean beforeViewChange(ViewChangeListener.ViewChangeEvent event) {
return false;
}
@Override
public void afterViewChange(ViewChangeListener.ViewChangeEvent event) {
}
}
......@@ -203,7 +203,8 @@ public class QuestionAnswerPanel extends CustomComponent
if( availableLanguages.size() > 1 ) {
availableLanguages.forEach(lang ->
{
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getFormatted())
mCssButtonLayout.add(new MButton(Language.getIso3Map().get(lang).getIso().toUpperCase())
.withDescription(Language.getIso3Map().get(lang).getFormatted())
.withListener(
clickEvent ->
{
......
package org.gesis.stardat.ui.view.question;
import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.UI;
import com.vaadin.ui.*;
import org.gesis.stardat.DDIEditor;
import org.gesis.stardat.config.Constants;
import org.gesis.stardat.domain.enumeration.Language;
import org.gesis.stardat.entity.*;
import org.gesis.stardat.events.EditorEvent;
import org.gesis.stardat.helper.TriggerableWindowMaster;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.service.QuestionCacheService;
......@@ -41,6 +37,7 @@ public class QuestionTranslateWindow extends BaseStoreCancelWindow implements Tr
private final EntityCreationService entityService;
private final UIEventBus eventBus;
private final ConfigurationService configService;
private MLabel languageCbFieldLabel = new MLabel( I18N.get( "checkbox.language" ) );
......@@ -101,16 +98,16 @@ public class QuestionTranslateWindow extends BaseStoreCancelWindow implements Tr
public QuestionTranslateWindow( QuestionConstruct construct, int sequence,
List<CodeList> codeLists, List<InterviewerInstruction> interviewerInstructions, List<Concept> concepts,
TriggerableWindowMaster master, QuestionCacheService cacheService, EntityCreationService entityService,
UIEventBus eventBus )
UIEventBus eventBus, ConfigurationService configService )
{
this( construct, null, sequence, codeLists, interviewerInstructions, concepts, master,
entityService, null, eventBus );
entityService, null, eventBus, configService );
}
public QuestionTranslateWindow( QuestionConstruct construct, QuestionConstruct constructPrevSibling, int sequence,
List<CodeList> codeLists, List<InterviewerInstruction> interviewerInstructions, List<Concept> concepts,
TriggerableWindowMaster master, EntityCreationService entityService,
Sequence masterSequence, UIEventBus eventBus )
Sequence masterSequence, UIEventBus eventBus, ConfigurationService configService )
{
super( WINDOW_NAME, new CssLayout() );
setWidth( "1024px" );
......@@ -126,6 +123,7 @@ public class QuestionTranslateWindow extends BaseStoreCancelWindow implements Tr
this.entityService = entityService;
this.masterSequence = masterSequence;
this.eventBus = eventBus;
this.configService = configService;
// // add save button
// MButton saveApplyButton = new MButton( I18N.get( WINDOW_NAME + ".storeStay" ) );
......@@ -137,7 +135,8 @@ public class QuestionTranslateWindow extends BaseStoreCancelWindow implements Tr
// getButtonLayout().add( saveApplyButton );
initComponents();
fillComponents();
fillComponents(languageComboBox.getValue().getIso3());
this.eventBus.subscribe( this, QuestionTranslateWindow.WINDOW_NAME );
}
......@@ -236,24 +235,35 @@ public class QuestionTranslateWindow extends BaseStoreCancelWindow implements Tr