Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/pc2ccs/pc2v9 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
clevengr committed Aug 19, 2021
2 parents 11fbfde + 026359b commit f306339
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 3 deletions.
96 changes: 96 additions & 0 deletions src/edu/csus/ecs/pc2/core/imports/clics/TeamAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package edu.csus.ecs.pc2.core.imports.clics;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.csus.ecs.pc2.core.model.JSONObjectMapper;

/**
* A JSON representation for the ICPC teams.json data.
*
* @author Douglas A. Lane <[email protected]>
*/
public class TeamAccount {

@JsonProperty
private int id;

@JsonProperty
private String icpc_id;

@JsonProperty
private String name;

@JsonProperty
private String display_name;

@JsonProperty
private String organization_id;

@JsonProperty
private List< String> group_ids;

// {"id": "1", "icpc_id": "449759", "name": "Kansas State University", "display_name": "Kansas State University", "organization_id": "k-state_edu", "group_ids": ["4"]},
/**
*
* 21 id "22" icpc_id "449752" name "Emory University" display_name "Emory University" organization_id "emory_edu" group_ids 0 "3"
*/

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getIcpc_id() {
return icpc_id;
}

public void setIcpc_id(String icpc_id) {
this.icpc_id = icpc_id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDisplay_name() {
return display_name;
}

public void setDisplay_name(String display_name) {
this.display_name = display_name;
}

public String getOrganization_id() {
return organization_id;
}

public void setOrganization_id(String organization_id) {
this.organization_id = organization_id;
}


public List<String> getGroup_ids() {
return group_ids;
}

public void setGroup_ids(List<String> group_ids) {
this.group_ids = group_ids;
}

public String toJSON() throws JsonProcessingException {

ObjectMapper om = JSONObjectMapper.getObjectMapper();
return om.writeValueAsString(this);
}
}
43 changes: 41 additions & 2 deletions src/edu/csus/ecs/pc2/shadow/RemoteEventFeedMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import edu.csus.ecs.pc2.core.IInternalController;
import edu.csus.ecs.pc2.core.Utilities;
import edu.csus.ecs.pc2.core.log.Log;
import edu.csus.ecs.pc2.core.model.ClientId;
import edu.csus.ecs.pc2.core.model.ClientType;
import edu.csus.ecs.pc2.core.model.ClientType.Type;
import edu.csus.ecs.pc2.core.model.IFile;
import edu.csus.ecs.pc2.core.model.RunUtilities;
import edu.csus.ecs.pc2.ui.ShadowCompareRunsPane;
Expand Down Expand Up @@ -190,11 +193,16 @@ public void run() {
// System.out.println("\nfound event: " + eventType + ":" + event); // TODO log this.

if ("submissions".equals(eventType)) {
// System.out.println("debug 22 found submission event");

if (isReadOnlyClient()) {
log.info("Skipping submission event due to being in read-only mode");
event = reader.readLine();
continue;
}

//process a submission event
try {
// log.log(Level.INFO, "Processing " + eventType + " event");
log.log(Level.INFO, "Processing " + eventType + " event");

//get a map of the data comprising the submission
Map<String, Object> submissionEventDataMap = (Map<String, Object>) eventMap.get("data");
Expand Down Expand Up @@ -419,6 +427,37 @@ public void run() {
} // end else
}

/**
* Returns an indication of whether the current client is a "read-only shadow" client.
*
* Currently, account "feeder1" is allowed to be a read-write Shadow (meaning, it has the ability
* to actually submit runs to the PC2 server when they are received from the Remote CCS); all
* other accounts are considered "read-only" -- meaning they can look at submissions,
* the scoreboards, etc. but they will not actually submit runs received from the Remote CCS to
* the PC2 server.
*
* TODO: extend this function to allow a broader definition and control of when a client
* is considered "read-only"; for example, managing this by Permissions and/or via
* Admin settings. See https://github.com/pc2ccs/pc2v9/issues/240.
*
* @return true if the current client is a "read-only Shadow" client; false if the client
* is allowed to do read-write operations (such as submitting a run from the Remote CCS
* to the PC2 server).
*/
private boolean isReadOnlyClient() {
ClientId clientId = pc2Controller.getContest().getClientId();
ClientType.Type clientType = clientId.getClientType();
int clientNum = clientId.getClientNumber();

if (clientType.equals(Type.FEEDER) && clientNum==1) {
//client is Feeder1; it is NOT a "read-only" client
return false;
} else {
//client is something other than Feeder1; it IS "read-only"
return true;
}
}

/**
* Initializes the Map<String,String> which holds mappings of judgement id's to corresponding submissions and judgement
* types (acronymns).
Expand Down
13 changes: 12 additions & 1 deletion src/edu/csus/ecs/pc2/tools/PC2Tools.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (C) 1989-2019 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2021 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.tools;

import java.util.Arrays;

import edu.csus.ecs.pc2.VersionInfo;
import edu.csus.ecs.pc2.api.reports.APIReports;
import edu.csus.ecs.pc2.core.ParseArguments;
import edu.csus.ecs.pc2.ui.team.CreateTeamsTSV;
import edu.csus.ecs.pc2.ui.team.SubmitterFromEF;

/**
Expand All @@ -29,6 +30,7 @@ private static void usage() {
"--gen - generate passwords to stdout, use --help --gen for usage", //
"--mer - prints mail merge file to stdtout, use --help --mer for usage", //
"--sr - submit runs from CLICS JSON EF, use --help --sr for usage", //
"--ttsv - convert teams.json to teams.tsv, use --help --ttsv for usage", //
"",

"--login LOGIN ", //
Expand Down Expand Up @@ -56,6 +58,11 @@ private static void usage() {
}

public void run(String[] args) {

if (args.length == 0) {
usage();
System.exit(4);
}

ParseArguments parseArguments = new ParseArguments(args);

Expand All @@ -76,6 +83,10 @@ public void run(String[] args) {

SubmitterFromEF.main(args);

} else if (parseArguments.isOptPresent("--ttsv")) {

CreateTeamsTSV.main(options);

} else if (parseArguments.isOptPresent("--mer")) {

PrintMergeFile.main(args);
Expand Down
Loading

0 comments on commit f306339

Please sign in to comment.