Skip to content

Commit

Permalink
support script template and programme effects
Browse files Browse the repository at this point in the history
also
* add countries
* role error only when both names are missing
* fix job index validation
  • Loading branch information
nittka committed Nov 19, 2023
1 parent 2f67989 commit ef4f592
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.resource.IEObjectDescription;
Expand All @@ -21,15 +23,19 @@
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher;
import org.tvtower.db.constants.Constants;
import org.tvtower.db.constants.EffectType;
import org.tvtower.db.constants.TVTEnum;
import org.tvtower.db.constants.TVTFlag;
import org.tvtower.db.database.DatabasePackage;
import org.tvtower.db.database.Effect;
import org.tvtower.db.database.GroupAttractivity;
import org.tvtower.db.database.Person;
import org.tvtower.db.database.StaffMember;
import org.tvtower.db.resource.DatabaseResourceDescriptionStrategy;
import org.tvtower.db.validation.DatabaseTime;

import com.google.common.base.Predicate;

/**
* See
* https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist
Expand Down Expand Up @@ -290,6 +296,14 @@ public void completeNewsData_HappenTime(EObject model, Assignment assignment, Co
createTimeProposals(acceptor, context);
}

@Override
public void complete_NewsData(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
selfClosingTagProposal("data", acceptor, context);
}
// End News-------------

// Effect
@Override
public void completeEffect_Trigger(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
Expand Down Expand Up @@ -321,18 +335,38 @@ public void completeEffect_Time(EObject model, Assignment assignment, ContentAss
}

@Override
public void complete_NewsData(EObject model, RuleCall ruleCall, ContentAssistContext context,
public void complete_Effect(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
selfClosingTagProposal("data", acceptor, context);
selfClosingTagProposal("effect", acceptor, context);
}

@Override
public void complete_Effect(EObject model, RuleCall ruleCall, ContentAssistContext context,
public void completeEffect_Guid(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
selfClosingTagProposal("effect", acceptor, context);
if(model instanceof Effect) {
EClass c=null;
String type = ((Effect)model).getType();
switch (type) {
case EffectType.PERSON:
c=DatabasePackage.eINSTANCE.getPerson();
break;
case EffectType.PROGRAMME_AVAILABILITY:
c=DatabasePackage.eINSTANCE.getProgramme();
break;
case EffectType.SCRIPT_AVAILABILITY:
c=DatabasePackage.eINSTANCE.getScriptTemplate();
break;
}
if(c!=null) {
final EClass compare= c;
Predicate<IEObjectDescription> p=desc-> desc.getEClass() == compare;
lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor,p);
}
}
}
// End News-------------
// End Effect-------------


// Person
@Override
public void completePerson_Gender(EObject model, Assignment assignment, ContentAssistContext context,
Expand Down
18 changes: 10 additions & 8 deletions org.tvtower.db/src/org/tvtower/db/Database.xtext
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ ScriptTemplate:
productionTime=ProductionTime?&
children=ScriptChildren?&
attractivity=GroupAttractivity?&
progDataModifiers=TemplateProgrammeModifiers?
progDataModifiers=TemplateProgrammeModifiers?&
effects=Effects?
)
'</''scripttemplate''>'
;
Expand Down Expand Up @@ -153,7 +154,8 @@ ScriptData:
('production_limit''='productionLimit=STRING)?&
('production_broadcast_limit''='broadcastLimit=STRING)?&
('production_broadcast_flags''='broadcastFlags=STRING)?&
('production_licence_flags''='licenceFlags=STRING)?
('production_licence_flags''='licenceFlags=STRING)?&
('available''='available=STRING)?
)
'/>'
;
Expand Down Expand Up @@ -336,9 +338,8 @@ TaskData:
('type''='type=STRING )&
('minAudienceAbsolute''='minAudienceAbs=STRING)?&
('minAudienceQuote''='minAudiencePercent=STRING)?&
//TODO genres/flats not yet supported (game.achievements.bmx todo line 145)
// ('limitToGenres''='limitToGenres=STRING)?&
// ('limitToFlags''='limitToFlags=STRING)?&
('limitToGenres''='limitToGenres=STRING)?&
('limitToFlags''='limitToFlags=STRING)?&
('minReachAbsolute''='minReachAbs=STRING)?&
('minReachPercentage''='minReachPercent=STRING)?&
('keyword1''='keyword1=STRING)?&
Expand Down Expand Up @@ -521,7 +522,7 @@ Effect:
('news''='news=[NewsItem|STRING])?&
('genre''='genre=STRING)?&
('choose''='choose=STRING)?&
('referenceGUID''='refs=[Person|STRING])?&
('guid''='guid=[ecore::EObject|STRING])?&//script or programme or person
('valueMin''='valueMin=STRING)?&
('valueMax''='valueMax=STRING)?&
('probability''='probability=STRING)?&
Expand Down Expand Up @@ -702,7 +703,8 @@ Programme:
releaseTime=ProgrammeReleaseTime?&
ratings=ProgrammeRatings?&
modifiers=Modifiers?&
data=ProgrammeData?
data=ProgrammeData?&
effects=Effects?
)
'</''programme''>'
;
Expand Down Expand Up @@ -829,9 +831,9 @@ ProgrammeData:
('broadcast_flags''='broadcastFlags=STRING)?&
('licence_broadcast_limit''='licenceBroadcastLimit=STRING)?&
('licence_broadcast_flags''='licenceBroadcastFlags=STRING)?&
('available''='available=STRING)?&
('price_mod''='priceMod=STRING)?
//TODO noch nicht alles unterstützt
//available, //noch kein sinnvoller Anwendungsfall in DB
)
'/>'
;
Expand Down
7 changes: 7 additions & 0 deletions org.tvtower.db/src/org/tvtower/db/constants/Country.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ public class Country extends TVTEnum {
Country() {
add("A","Austria");
add("AFG","Afghanistan");
add("AM","Armenia");
add("AUS","Australia");
add("B","Belgium");
add("BIH","Bosnia and Herzegovina");
add("BM","Bermudas");
add("BG","Bulgeria");
add("BOL","Bolivia");
add("BR","Brazil");
add("BW","Republic of Botswana");
Expand All @@ -23,17 +26,21 @@ public class Country extends TVTEnum {
add("DK","Denmark");
add("E","Spain");
add("F","France");
add("FIN","Finland");
add("GB","United Kingdom");
add("GH","Ghana");
add("GR", "Greece");
add("H","Hungary");
add("HK","Hongkong");
add("HR","Kroatia");
add("I","Italy");
add("IL","Israel");
add("IND","India");
add("IRL","Ireland");
add("J","Japan");
add("KN","Greenland");
add("KSA","Saudi Arabia");
add("LT","Lithuania");
add("MEX","Mexico");
add("NL","Netherlands");
add("NZ","New Zealand");
Expand Down
4 changes: 4 additions & 0 deletions org.tvtower.db/src/org/tvtower/db/constants/EffectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ public class EffectType extends TVTEnum {
public static final String PERSON="modifyPersonPopularity";
public static final String GENRE="modifyMovieGenrePopularity";
public static final String NEWS_AVAILABILITY="modifyNewsAvailability";
public static final String PROGRAMME_AVAILABILITY="modifyProgrammeAvailability";
public static final String SCRIPT_AVAILABILITY="modifyScriptAvailability";

EffectType() {
add(NEWS, "news");
add(NEWS_CHOICE, "one of several news");
add(NEWS_AVAILABILITY, "news availability");
add(PROGRAMME_AVAILABILITY, "programme availability");
add(SCRIPT_AVAILABILITY, "script availability");
add(PERSON, "change person popularity");
add(GENRE, "change genre popularity");
}
Expand Down
62 changes: 42 additions & 20 deletions org.tvtower.db/src/org/tvtower/db/validation/NewsValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.tvtower.db.database.Effect;
import org.tvtower.db.database.NewsData;
import org.tvtower.db.database.NewsItem;
import org.tvtower.db.database.Person;
import org.tvtower.db.database.Programme;
import org.tvtower.db.database.ScriptTemplate;

import com.google.common.base.Strings;

Expand Down Expand Up @@ -148,6 +151,7 @@ private void checkTriggeredNews(NewsItem parentNews, Effect e, NewsItem triggere
}
}

//TODO extend check effects to programme and scripts
@Check
public void checkEffect(Effect e) {
Constants.triggerType.isValidValue(e.getTrigger(), "trigger", true)
Expand All @@ -173,31 +177,46 @@ public void checkEffect(Effect e) {
.ifPresent(err -> error(err, $.getEffect_Enable()));

if (e.getType() != null) {
boolean checkMinMax = false;
boolean genreExpected = false;
boolean refExpected = false;
boolean choiceExpected = false;
boolean enableExpected = false;
boolean newsExpected = false;
Boolean checkMinMax = Boolean.FALSE;
Boolean genreExpected = Boolean.FALSE;
Boolean guidExpected = Boolean.FALSE;
Boolean choiceExpected = Boolean.FALSE;
Boolean enableExpected = Boolean.FALSE;
Boolean newsExpected = Boolean.FALSE;
Class expectedClass= null;

switch (e.getType()) {
case EffectType.NEWS:
newsExpected = true;
newsExpected = Boolean.TRUE;
expectedClass=NewsItem.class;
break;
case EffectType.NEWS_CHOICE:
choiceExpected = true;
choiceExpected = Boolean.TRUE;
expectedClass=NewsItem.class;
break;
case EffectType.PERSON:
checkMinMax = true;
refExpected = true;
checkMinMax = Boolean.TRUE;
guidExpected = Boolean.TRUE;
expectedClass=Person.class;
break;
case EffectType.GENRE:
checkMinMax = true;
genreExpected = true;
checkMinMax = Boolean.TRUE;
genreExpected = Boolean.TRUE;
break;
case EffectType.NEWS_AVAILABILITY:
newsExpected = true;
enableExpected = true;
newsExpected = Boolean.TRUE;
enableExpected = Boolean.TRUE;
expectedClass=NewsItem.class;
break;
case EffectType.SCRIPT_AVAILABILITY:
guidExpected = Boolean.TRUE;
enableExpected = null;
expectedClass=ScriptTemplate.class;
break;
case EffectType.PROGRAMME_AVAILABILITY:
guidExpected = Boolean.TRUE;
enableExpected = null;
expectedClass=Programme.class;
break;
default:
break;
Expand All @@ -209,8 +228,8 @@ public void checkEffect(Effect e) {
effectTypeField("genre", e.getGenre(), genreExpected);
effectTypeField("choice", e.getChoose(), choiceExpected);
effectTypeField("enable", e.getEnable(), enableExpected);
referenceField("reference", e.getRefs(), refExpected);
referenceField("news", e.getNews(), newsExpected);
referenceField("guid", e.getGuid(), guidExpected, expectedClass);
referenceField("news", e.getNews(), newsExpected, expectedClass);

// check choices
if (e.getChoose() != null) {
Expand Down Expand Up @@ -245,19 +264,22 @@ private void assertChoiceValueNotSet(Object value, EStructuralFeature f) {
}
}

private void referenceField(String field, Object value, boolean expected) {
private void referenceField(String field, Object value, boolean expected, Class expectedRefType) {
if(expected && value ==null) {
error(field+ " expected for this effect type", $.getEffect_Type());
}else if(!expected&& value!=null) {
error(field + " not allowed for this effect type", $.getEffect_Type());
}
if(expected &&value!=null &&! (expectedRefType.isAssignableFrom(value.getClass()))) {
error(expectedRefType.getSimpleName() + " expected", $.getEffect_Guid());
}
}

private void effectTypeField(String field, String fieldValue, boolean expected) {
private void effectTypeField(String field, String fieldValue, Boolean expected) {
boolean present = !Strings.isNullOrEmpty(fieldValue);
if (expected && !present) {
if (expected==Boolean.TRUE && !present) {
error(field + " expected for this effect type", $.getEffect_Type());
} else if (!expected && present) {
} else if (expected==Boolean.FALSE && present) {
error(field + " not allowed for this effect type", $.getEffect_Type());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ private boolean isInsignificant(Person p) {

@Check
public void checkRole(ProgrammeRole r) {
CommonValidation.getValueMissingError("first_name", r.getFirstName())
.ifPresent(e -> warning(e, $.getProgrammeRole_FirstName()));
CommonValidation.getValueMissingError("last_name", r.getLastName())
.ifPresent(e -> warning(e, $.getProgrammeRole_LastName()));
CommonValidation.getValueMissingError("name", r.getFirstName(), r.getLastName())
.ifPresent(e -> error(e, $.getProgrammeRole_FirstName()));
// CommonValidation.getValueMissingError("last_name", r.getLastName())
// .ifPresent(e -> warning(e, $.getProgrammeRole_LastName()));
CommonValidation.getCountryError(r.getCountry(), false).ifPresent(e -> error(e, $.getProgrammeRole_Country()));
Constants.gender.isValidValue(r.getGender(), "gender", false)
.ifPresent(e -> error(e, $.getProgrammeRole_Gender()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.tvtower.db.database.StaffMember;

import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;

//TODO GroupAttractivitiy valieren (nach Umschreiben)
public class ProgrammeValidator extends AbstractDatabaseValidator {
Expand Down Expand Up @@ -104,6 +106,10 @@ public void checkProgrammeData(ProgrammeData d) {
Constants.programmGenre.isValidValue(d.getMaingenre(), "maingenre", false)
.ifPresent(e -> error(e, $.getProgrammeData_Maingenre()));
Constants.programmGenre.isValidList(d.getSubgenre()).ifPresent(e -> error(e, $.getProgrammeData_Subgenre()));
if (!Strings.isNullOrEmpty(d.getSubgenre()) && !Strings.isNullOrEmpty(d.getMaingenre())) {
Splitter.on(",").trimResults().splitToStream(d.getSubgenre()).filter(g -> g.equals(d.getMaingenre()))
.findFirst().ifPresent(g -> error("main genre duplicate", $.getProgrammeData_Subgenre()));
}
Constants.programmeFlag.isValidFlag(d.getFlags(), "flags", false)
.ifPresent(e -> error(e, $.getProgrammeData_Flags()));
Constants.licenceFlag.isValidFlag(d.getLicenceFlags(), "licence_flags", false)
Expand All @@ -126,6 +132,8 @@ public void checkProgrammeData(ProgrammeData d) {
.ifPresent(e -> error(e, $.getProgrammeData_LicenceBroadcastFlags()));
ensureLimitHandling(d, d.getBroadcastLimit(), $.getProgrammeData_BroadcastLimit());
ensureLimitHandling(d, d.getLicenceBroadcastLimit(), $.getProgrammeData_LicenceBroadcastLimit());
Constants._boolean.isValidValue(d.getAvailable(), "available", false)
.ifPresent(e -> error(e, $.getProgrammeData_Available()));
}

private void ensureLimitHandling(ProgrammeData d, String limit, EStructuralFeature limitFeature) {
Expand Down
Loading

0 comments on commit ef4f592

Please sign in to comment.