Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story/vspc 213 #302

Merged
merged 29 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5b25410
[story/VSPC-213]added exhibitionlanguage codes
May 12, 2022
c3f1f8b
[story/VSPC-213] added configuration for language codes and labels
May 18, 2022
c770d63
[story/VSPC-213] added support for multiple exhibition languages
May 23, 2022
959b957
[story/VSPC-213] added test cases
May 23, 2022
bf91424
[story/VSPC-213] added code for default language
May 23, 2022
cbf9519
[VSPC-213] refactor
May 23, 2022
f3285d4
[story/VSPC-213] codefactor
May 23, 2022
7ac5aed
[story/VSPC-213] refactor
May 23, 2022
ff7a491
[story/VSPC-213] revert unwanted file changes
May 23, 2022
1e883bd
[story/VSPC-213] review comments
May 26, 2022
e313921
[story/VSPC-213] modified prefix of exhibition language
May 26, 2022
52e2fd5
[story/VSPC-213] added exceptions. modified exhibition language config
Jun 6, 2022
4575ca4
[story/VSPC-213] added check for only one default language per exhibi…
Jun 7, 2022
f57fa0a
[story/VSPC-213] code factor
Jun 7, 2022
7a8e502
[story/VSPC-213] code factor
Jun 7, 2022
0784a7b
[story/VSPC-213] refactor
Jun 7, 2022
5382226
[story/VSPC-213] refactor
Jun 7, 2022
00cc39f
[story/VSPC-213] added interface for Exhibition language
Jun 10, 2022
98a3eb8
[story/VSPC-213] code factor
Jun 10, 2022
07f65c6
[story/VSPC-213] Merged develop into story/VSPC-213
Jun 16, 2022
00d8754
[story/VSPC-213] langauge list config not found added to exception ha…
Jun 16, 2022
1c566b7
[story/VSPC-213] refactor
Jun 16, 2022
39b9f8b
[story/VSPC-213] modified language list config not found exception
Jun 17, 2022
bcd81b6
[story/VSPC-213] refactor
Jun 17, 2022
72f033b
[story/VSPC-213] review comments
Jun 20, 2022
dcac0ab
[story/VSPC-213] removed LanguageListConfigException declaration
Jun 21, 2022
33712c2
[story/VSPC-213] refactor
Jun 21, 2022
550a4ee
[story/VSPC-213] remove exhibitionlanguage if unselected
Jun 27, 2022
4cea3c2
[story/VSPC-213] added test case
Jun 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package edu.asu.diging.vspace.config;

public interface ConfigConstants {
public final static String EXHIBITION_LANGUAGE_LIST_PROPERTY= "exhibition-language-list";

public final static String LABEL= "label";

public final static String CODE= "code";

public final static String LANGUAGES= "languages";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.asu.diging.vspace.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.stereotype.Component;

import edu.asu.diging.vspace.core.model.impl.ExhibitionLanguage;
import org.springframework.core.env.MutablePropertySources;


@Component
@PropertySource(value= "classpath:exhibitionLanguages.properties" , factory=JsonPropertySourceFactory.class)
@Configuration
public class ExhibitionLanguageConfig {

@Autowired
private Environment environment;

private List<Map> exhibitionLanguageList = new ArrayList<Map>();

/**
* Fetches the configured language list from environment property source and stores in exhibitionLanguageList
*
*/
@PostConstruct
public void init() {

org.springframework.core.env.PropertySource<?> propertySource = ((AbstractEnvironment) environment).getPropertySources().get(ConfigConstants.EXHIBITION_LANGUAGE_LIST_PROPERTY);
if( propertySource != null ) {
Map<String, Object> languageMap = (Map<String, Object>) propertySource.getSource();
exhibitionLanguageList = (List<Map>) languageMap.get(ConfigConstants.LANGUAGES);
}

}

public List<Map> getExhibitionLanguageList() {
return exhibitionLanguageList;
}
public void setExhibitionLanguageList(List<Map> exhibitionLanguageList) {
this.exhibitionLanguageList = exhibitionLanguageList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.asu.diging.vspace.config;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonPropertySourceFactory implements PropertySourceFactory {


/**
* Converts language json read from properties file to a map and stores in property source.
*
*/
@Override
public org.springframework.core.env.PropertySource<?> createPropertySource(String name, EncodedResource resource)
throws IOException {
Map<String, Object> readValue = new ObjectMapper()
.readValue(resource.getInputStream(), Map.class);
return new MapPropertySource(ConfigConstants.EXHIBITION_LANGUAGE_LIST_PROPERTY, readValue);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.asu.diging.vspace.core.exception;

public class LanguageListConfigurationNotFound extends Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a runtime exception and exception class names should end in Exception


private static final long serialVersionUID = 1L;

public LanguageListConfigurationNotFound() {
super();
}

public LanguageListConfigurationNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public LanguageListConfigurationNotFound(String message, Throwable cause) {
super(message, cause);
}

public LanguageListConfigurationNotFound(String message) {
super(message);
}

public LanguageListConfigurationNotFound(Throwable cause) {
super(cause);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package edu.asu.diging.vspace.core.model;

import java.util.List;
import java.util.Set;

import edu.asu.diging.vspace.core.model.impl.ExhibitionLanguage;

public interface IExhibition extends IVSpaceElement {

/*
Expand All @@ -26,4 +31,6 @@ public interface IExhibition extends IVSpaceElement {

void setAboutPageConfigured(boolean aboutPageConfigured);

List<IExhibitionLanguage> getLanguages();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.asu.diging.vspace.core.model;

public interface IExhibitionLanguage extends IVSpaceElement {

String getCode();

String getLabel();

boolean isDefault();

void setDefault(boolean isDefault);

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package edu.asu.diging.vspace.core.model.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import edu.asu.diging.vspace.core.model.ExhibitionModes;
import edu.asu.diging.vspace.core.model.IContentBlock;
import edu.asu.diging.vspace.core.model.IExhibition;
import edu.asu.diging.vspace.core.model.IExhibitionLanguage;
import edu.asu.diging.vspace.core.model.ISpace;

/**
Expand Down Expand Up @@ -37,6 +47,9 @@ public class Exhibition extends VSpaceElement implements IExhibition {
private String customMessage;

private boolean aboutPageConfigured;

@OneToMany(targetEntity = ExhibitionLanguage.class, mappedBy = "exhibition", cascade = CascadeType.ALL)
private List<IExhibitionLanguage> languages = new ArrayList<IExhibitionLanguage>();

/*
* (non-Javadoc)
Expand Down Expand Up @@ -116,4 +129,31 @@ public void setAboutPageConfigured(boolean aboutPageConfigured) {
this.aboutPageConfigured = aboutPageConfigured;
}

public List<IExhibitionLanguage> getLanguages() {
return languages;
}

public void setLanguages(List<IExhibitionLanguage> languages) {
this.languages = languages;
}


@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Exhibition other = (Exhibition) obj;
return Objects.equals(id, other.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge with line 154

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I didn't see this before but first all getters/setters then hashcode/equals methods.



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package edu.asu.diging.vspace.core.model.impl;

import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import edu.asu.diging.vspace.core.model.IExhibitionLanguage;

@Entity
public class ExhibitionLanguage extends VSpaceElement implements IExhibitionLanguage {

@Id
@GeneratedValue(generator = "exhibit_language_id_generator")
@GenericGenerator(name = "exhibit_language_id_generator", parameters = @Parameter(name = "prefix", value = "LANG"), strategy = "edu.asu.diging.vspace.core.data.IdGenerator")
private String id;

private String label;

@ManyToOne(targetEntity = Exhibition.class)
private Exhibition exhibition;

private String code;

private boolean isDefault;

public ExhibitionLanguage() {
super();
}

public ExhibitionLanguage(String label, String code, Exhibition exhibition) {
this.label=label;
this.code=code;
this.exhibition=exhibition;
}

@Override
public String getId() {
return id;
}

@Override
public void setId(String id) {
this.setId(id);
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public Exhibition getExhibition() {
return exhibition;
}

public void setExhibition(Exhibition exhibition) {
this.exhibition = exhibition;
}

@Override
public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@Override
public boolean isDefault() {
return isDefault;
}

@Override
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}

@Override
public int hashCode() {
return Objects.hash(code, exhibition, label);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ExhibitionLanguage other = (ExhibitionLanguage) obj;
return Objects.equals(code, other.code) && Objects.equals(exhibition, other.exhibition)
&& Objects.equals(label, other.label);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import edu.asu.diging.vspace.core.exception.LanguageListConfigurationNotFound;
import edu.asu.diging.vspace.core.model.IExhibition;
import edu.asu.diging.vspace.core.model.impl.Exhibition;

Expand Down Expand Up @@ -34,4 +35,6 @@ public interface IExhibitionManager {

IExhibition getStartExhibition();

void updateExhibitionLanguages(Exhibition exhibition, List<String> languages, String defaultLanguage) throws LanguageListConfigurationNotFound;

}
Loading