Skip to content

Commit

Permalink
feat: endpoint execute schedule permission [BACKLOG-40051]
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrasil committed Mar 19, 2024
1 parent 9d0e919 commit 1199479
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,56 @@ private void init() {
RequestBuilder builder = new RequestBuilder( RequestBuilder.GET, url );
builder.setHeader( CONTENT_TYPE, APPLICATION_JSON );
builder.setHeader( IF_MODIFIED_SINCE, IF_MODIFIED_SINCE_DATE );
canSchedule = true;
canSchedule = false;

try {
builder.sendRequest( null, new RequestCallback() {
@Override
public void onError( Request request, Throwable throwable ) {
setupPerspectiveManager();
canExecuteSchedules();
}

@Override
public void onResponseReceived( Request request, Response response ) {
if ( response.getStatusCode() == 200 ) {
canSchedule = "true".equals( response.getText() );

if ( canSchedule ) {
setupPerspectiveManager();
return;
}
}

setupPerspectiveManager();
canExecuteSchedules();
}
} );
} catch ( Exception ignored ) {
// ignore
}
}

private void canExecuteSchedules() {
try {
final String url = MantleUtils.getSchedulerPluginContextURL() + "api/scheduler/canExecuteSchedules?ts="
+ System.currentTimeMillis(); //$NON-NLS-1$
RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.GET, url );
requestBuilder.setHeader( CONTENT_TYPE, APPLICATION_JSON );
requestBuilder.setHeader( IF_MODIFIED_SINCE, IF_MODIFIED_SINCE_DATE );
requestBuilder.sendRequest( null, new RequestCallback() {
public void onError( Request request, Throwable caught ) {
setupPerspectiveManager();
}

public void onResponseReceived( Request request, Response response ) {
canSchedule = "true".equalsIgnoreCase( response.getText() ); //$NON-NLS-1$
setupPerspectiveManager();
}
} );
} catch ( RequestException ignored ) {
// ignore
}
}

private void setupPerspectiveManager() {
final String url =
GWT.getHostPageBaseURL() + "api/plugin-manager/perspectives?ts=" + System.currentTimeMillis(); //$NON-NLS-1$
Expand Down

0 comments on commit 1199479

Please sign in to comment.