Last active
September 1, 2017 20:06
-
-
Save akwodkiewicz/0d1c5a22029cf2eea36ee7f6c8b504d1 to your computer and use it in GitHub Desktop.
Problem skryptowy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AbstractSdmFactory { | |
private final String url | |
private final long rfcId | |
private final long reqId | |
public Ticket createTicket(long issueTypeId, LinkedHashMap attributes) { | |
if (this.rfcId == issueTypeId) { | |
return new Rfc('attributes': attributes) | |
} else if (this.reqId == issueTypeId) { | |
return new Request('attributes': attributes) | |
} else { | |
throw new IllegalArgumentException('Wrong issue type') | |
} | |
} | |
public Ticket createTicketFromRefNum(long issueTypeId, String refNum) { | |
if (this.rfcId == issueTypeId) { | |
return new Rfc('refNum': refNum) | |
} else if (this.reqId == issueTypeId) { | |
return new Request('refNum': refNum) | |
} else { | |
throw new IllegalArgumentException('Wrong issue type') | |
} | |
} | |
public User createUser(String username) { | |
return new User('username': username) | |
} | |
public WebServiceManager createWebServiceManager() { | |
return new WebServiceManager(url) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProdSdmFactory extends AbstractSdmFactory { | |
private final String url = 'http://example.com/prod' | |
private final long rfcId = 2000 | |
private final long reqId = 1001 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Request extends Ticket { | |
public final String requredStatus = 'DONE' | |
public final String refNumCode = 'ref_num' | |
public StreamingMarkupBuilder buildXml() { | |
def builder = new StreamingMarkupBuilder() | |
builder.bind('something that is totally different than before and makes this method immovable to base class') | |
return builder | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Rfc extends Ticket { | |
public final String requredStatus = 'FINISHED' | |
public final String refNumCode = 'chg_ref_num' | |
public StreamingMarkupBuilder buildXml() { | |
def builder = new StreamingMarkupBuilder() | |
builder.bind('something about Rfc') | |
return builder | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input: Issue issue | |
AbstractSdmFactory factory | |
if (Utils.isTestEnv()) { | |
factory = new TestSdmFactory() | |
} else { | |
factory = new ProdSdmFactory() | |
} | |
WebServiceManager manager = factory.createWebServiceManager() | |
Ticket ticket = factory.createTicket(issue.getIssueTypeId(), issue.getAttributes()) | |
if (manager.createInSdm(ticket) == 200) { | |
println 'Creation successful' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input: Issue issue | |
AbstractSdmFactory factory | |
if (Utils.isTestEnv()) { | |
factory = new TestSdmFactory() | |
} else { | |
factory = new ProdSdmFactory() | |
} | |
WebServiceManager manager = factory.createWebServiceManager() | |
Ticket ticket = factory.createTickeFromRefNum(issue.getIssueTypeId(), issue.getRefNum()) | |
if (manager.hasRequiredStatus(ticket)) { | |
println 'Ticket processed' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestSdmFactory extends AbstractSdmFactory { | |
private final String url = 'http://example.com/test' | |
private final long rfcId = 42 | |
private final long reqId = 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Ticket { | |
public final String requiredStatus | |
public LinkedHashMap attributes | |
public String refNum | |
public final String refNumCode | |
public abstract StreamingMarkupBuilder buildXml() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User { | |
public final String username | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WebServiceManager { | |
private final String url | |
private WebServiceManager(String u) { | |
this.url = u | |
} | |
public int createinSdm(Ticket t) { | |
def xml = t.buildXml() | |
def status = Utils.sendXml(this.url, xml) // Utils.groovy is a custom-made utility class | |
return status | |
} | |
public bool hasRequiredStatus(Ticket t) { | |
return t.requiredStatus == Utils.select(this.url, 'status', "${t.refNumCode} LIKE '${t.refNum}'") | |
} | |
public int getUserId(User user) { | |
return Utils.select(this.url, 'id', "username LIKE '${user.username}") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment