Commit 98d4c446 authored by Nugraha, Sigit's avatar Nugraha, Sigit
Browse files

Add group language and dialect attribute and storage function

parent de39f952
Pipeline #15155 passed with stage
in 2 minutes and 26 seconds
package org.gesis.stardat.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* A Group.
*/
......@@ -48,6 +47,12 @@ public class Group implements Serializable {
@Column(name = "info")
private String info;
@Column(name = "language")
private String language;
@Column(name = "dialect")
private String dialect;
@ManyToMany(mappedBy = "groups")
@JsonIgnore
private Set<User> users = new HashSet<>();
......@@ -196,6 +201,22 @@ public class Group implements Serializable {
this.info = info;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getDialect() {
return dialect;
}
public void setDialect(String dialect) {
this.dialect = dialect;
}
@Override
public boolean equals(Object o) {
if (this == o) {
......
package org.gesis.stardat.service;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.vaadin.ui.UI;
import org.gesis.stardat.domain.enumeration.Language;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,7 +9,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import com.vaadin.ui.UI;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
public class ConfigurationService {
......@@ -32,6 +31,12 @@ public class ConfigurationService {
@Value("${app.language.source.iso3.enable}")
private String enableLanguageByIso3;
@Value("${group.language.default}")
String groupLanguageDefault;
@Value("${group.dialectDefinition.default}")
String groupDialectDefinitionDefault;
public String getServerContextPath() {
return serverContextPath;
......@@ -82,4 +87,22 @@ public class ConfigurationService {
}
return languages;
}
public String getGroupLanguageDefault() {
return groupLanguageDefault;
}
public Language getGroupLanguageEnumDefault() {
Language language = null;
try {
language = Language.getByIso3(groupLanguageDefault);
} catch (Exception e) {
}
return language;
}
public String getGroupDialectDefinitionDefault() {
return groupDialectDefinitionDefault;
}
}
......@@ -25,6 +25,10 @@ public class GroupDTO implements Serializable {
private String headerImage;
private String info;
private String language;
private String dialect;
public Long getId() {
return id;
......@@ -98,6 +102,22 @@ public class GroupDTO implements Serializable {
this.info = info;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getDialect() {
return dialect;
}
public void setDialect(String dialect) {
this.dialect = dialect;
}
@Override
public boolean equals(Object o) {
if (this == o) {
......
package org.gesis.stardat.service.impl;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.gesis.stardat.domain.Group;
import org.gesis.stardat.repository.GroupRepository;
import org.gesis.stardat.service.GroupService;
......@@ -11,9 +7,14 @@ import org.gesis.stardat.service.dto.GroupDTO;
import org.gesis.stardat.service.mapper.GroupMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Service Implementation for managing Group.
*/
......@@ -21,6 +22,12 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
public class GroupServiceImpl implements GroupService {
@Value("${group.language.default}")
String groupLanguageDefault;
@Value("${group.dialectDefinition.default}")
String groupDialectDefinitionDefault;
private final Logger log = LoggerFactory.getLogger(GroupServiceImpl.class);
private final GroupRepository groupRepository;
......@@ -42,6 +49,10 @@ public class GroupServiceImpl implements GroupService {
public GroupDTO save(GroupDTO groupDTO) {
log.debug("Request to save Group : {}", groupDTO);
Group group = groupMapper.toEntity(groupDTO);
if( group.getLanguage() == null )
group.setLanguage( groupLanguageDefault );
if( group.getDialect() == null )
group.setDialect( groupDialectDefinitionDefault );
group = groupRepository.save(group);
return groupMapper.toDto(group);
}
......
......@@ -164,7 +164,7 @@ public class AdminView extends AbstractAdminView implements Translatable
mainContainer.add( manageUserLayout );
break;
case MANAGE_GROUP:
mainContainer.add( new ManageGroupLayout( groupService, userService, entityService ) );
mainContainer.add( new ManageGroupLayout( groupService, userService, entityService, configService ) );
break;
case MANAGE_USER_ROLE:
mainContainer.add( new ManageUserRoleLayout( i18n, userService, roleService ) );
......
package org.gesis.stardat.ui.admin.form;
import com.vaadin.data.Binder;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.themes.ValoTheme;
import org.gesis.stardat.domain.enumeration.Language;
import org.gesis.stardat.entity.StudyGroup;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.GroupService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.service.UserService;
import org.gesis.stardat.service.*;
import org.gesis.stardat.service.dto.GroupDTO;
import org.gesis.stardat.service.dto.UserDTO;
import org.gesis.stardat.ui.admin.layout.ManageGroupLayout;
......@@ -31,6 +30,7 @@ public class GroupForm extends FormLayout implements Translatable {
private TextArea description = new TextArea("Description");
private MTextField email = new MTextField("Group e-mail");
private UploadGroupLogo uploadGroupLogo = new UploadGroupLogo();
private ComboBox<Language> languageComboBox = new ComboBox<>();
private MButton save = new MButton("Save");
private MButton delete = new MButton("Delete");
......@@ -43,7 +43,8 @@ public class GroupForm extends FormLayout implements Translatable {
private Binder<GroupDTO> binder = new Binder<>(GroupDTO.class);
private final EntityCreationService creationService;
public GroupForm( ManageGroupLayout manageGroupLayout, GroupService groupService, UserService userService, EntityCreationService creationService) {
public GroupForm( ManageGroupLayout manageGroupLayout, GroupService groupService, UserService userService, EntityCreationService creationService,
ConfigurationService configurationService) {
this.manageGroupLayout = manageGroupLayout;
this.groupService = groupService;
this.userService = userService;
......@@ -55,7 +56,7 @@ public class GroupForm extends FormLayout implements Translatable {
setSizeUndefined();
HorizontalLayout buttons = new HorizontalLayout(save, delete);
uploadGroupLogo.setCaption("Header logo");
addComponents(name, description, email, uploadGroupLogo, buttons);
save.setStyleName(ValoTheme.BUTTON_PRIMARY);
......@@ -63,6 +64,19 @@ public class GroupForm extends FormLayout implements Translatable {
save.addClickListener(e -> this.save());
delete.addClickListener(e -> this.delete());
languageComboBox.setTextInputAllowed( false );
languageComboBox.setEmptySelectionAllowed( false );
languageComboBox.setCaption(I18N.get("language.source"));
languageComboBox.setItemCaptionGenerator( Language::getFormatted );
final List<Language> languages = configurationService.getSourceLanguagesByIso3();
if( !languages.isEmpty() ) {
languageComboBox.setItems(languages);
languageComboBox.setSelectedItem(languages.get(0));
}
if( configurationService.getGroupLanguageEnumDefault() != null )
languageComboBox.setSelectedItem(configurationService.getGroupLanguageEnumDefault());
addComponents(name, description, email, uploadGroupLogo, languageComboBox, buttons);
}
public void setGroupDTO(GroupDTO groupDTO) {
......@@ -105,12 +119,17 @@ public class GroupForm extends FormLayout implements Translatable {
private void save() {
if( groupDTO == null || groupDTO.getName().isEmpty())
return;
final Language selectedLanguage = languageComboBox.getValue();
groupDTO.setLanguage( selectedLanguage.getIso3() );
groupDTO.setDialect( selectedLanguage.getStudyDialect() );
if( groupDTO.getId() == null ) {
final StudyGroup newStudyGroup = creationService.createNewStudyGroup(groupDTO.getName(), groupDTO.getDescription());
groupDTO.setGroupReference( newStudyGroup.getId());
} else {
// TODO: store modification
// TODO: store modification in flatDb
}
groupService.save(groupDTO);
......
......@@ -5,10 +5,7 @@ import com.vaadin.shared.ui.ContentMode;
import com.vaadin.shared.ui.ValueChangeMode;
import com.vaadin.ui.themes.ValoTheme;
import org.gesis.stardat.entity.StudyGroup;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.GroupService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.service.UserService;
import org.gesis.stardat.service.*;
import org.gesis.stardat.service.dto.GroupDTO;
import org.gesis.stardat.ui.admin.form.GroupForm;
import org.vaadin.spring.i18n.support.Translatable;
......@@ -40,11 +37,12 @@ public class ManageGroupLayout extends MCssLayout implements Translatable {
private MButton addBtn = new MButton();
private GroupForm form;
public ManageGroupLayout(GroupService gService, UserService uService, EntityCreationService creationService) {
public ManageGroupLayout(GroupService gService, UserService uService, EntityCreationService creationService,
ConfigurationService configurationService) {
super();
this.groupService = gService;
this.creationService = creationService;
this.form = new GroupForm(this, gService, uService, creationService);
this.form = new GroupForm(this, gService, uService, creationService, configurationService);
this.groupUserLayout = new ManageGroupUserLayout(gService, uService);
init();
}
......
......@@ -51,3 +51,5 @@ server.http2.enabled=true
app.language.source.iso3.enable=en-MK,de-DE
app.language.target.iso3.enable=en-MK,de-DE
group.language.default = de-DE
group.dialectDefinition.default = gesisGroup32
......@@ -6,19 +6,19 @@
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<appender name="gelf" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<host>udp:10.6.13.174</host>
<port>12201</port>
<version>1.0</version>
<facility>java-test</facility>
<extractStackTrace>true</extractStackTrace>
<filterStackTrace>true</filterStackTrace>
<includeLocation>true</includeLocation>
<mdcProfiling>true</mdcProfiling>
<timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
<maximumMessageSize>8192</maximumMessageSize>
<includeFullMdc>true</includeFullMdc>
</appender>
<!-- <appender name="gelf" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">-->
<!-- <host>udp:10.6.13.174</host>-->
<!-- <port>12201</port>-->
<!-- <version>1.0</version>-->
<!-- <facility>java-test</facility>-->
<!-- <extractStackTrace>true</extractStackTrace>-->
<!-- <filterStackTrace>true</filterStackTrace>-->
<!-- <includeLocation>true</includeLocation>-->
<!-- <mdcProfiling>true</mdcProfiling>-->
<!-- <timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>-->
<!-- <maximumMessageSize>8192</maximumMessageSize>-->
<!-- <includeFullMdc>true</includeFullMdc>-->
<!-- </appender>-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......@@ -27,9 +27,9 @@
</encoder>
</appender>
<logger name="actionLog" level="INFO" additivity="false">
<appender-ref ref="gelf" />
</logger>
<!-- <logger name="actionLog" level="INFO" additivity="false">-->
<!-- <appender-ref ref="gelf" />-->
<!-- </logger>-->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file> ${LOG_FILE} </file>
......@@ -55,4 +55,4 @@
</root>
</configuration>
\ No newline at end of file
</configuration>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment