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

Implement URL Management Feature in Universal Migration Tool #31

Open
wants to merge 2 commits into
base: react
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions src/com/hannonhill/umt/struts/ProjectPropertiesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.nio.charset.StandardCharsets;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.xml.rpc.ServiceException;

import com.google.gson.Gson;
import org.apache.commons.lang.xwork.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -36,6 +38,8 @@ public class ProjectPropertiesAction extends BaseAction
{
private static final long serialVersionUID = -845484679818107782L;

private static final List<String> urls = new ArrayList<>();

private String url = "";
private String username = "";
private String password = "";
Expand Down Expand Up @@ -267,6 +271,35 @@ private void verifyConnectivity()
addActionError("Could not read a site for unknown reason");
}

public String addUrl() {
urls.add(url);
return toJson();
}

public String getUrls() {
return toJson();
}

public String updateUrl() {
String[] parts = url.split(" ");
urls.remove(parts[0].trim());
urls.add(parts[1].trim());
return toJson();
}

public String deleteUrl() {
urls.remove(url);
return toJson();
}

private String toJson() {
Gson gson = new Gson();
String json = gson.toJson(ProjectPropertiesAction.urls);
inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
return SUCCESS;
}


/**
* @return Returns the url.
*/
Expand Down
55 changes: 48 additions & 7 deletions src/react-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.2.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
5 changes: 4 additions & 1 deletion src/react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import './App.css';
import SavedUrlsManager from "./components/SavedUrlsManager";

function App() {
return (
<div className="App">React app here</div>
<div className="App">
<SavedUrlsManager />
</div>
);
}

Expand Down
176 changes: 176 additions & 0 deletions src/react-app/src/components/SavedUrlsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import React,{ useState, useEffect } from 'react';

const SavedUrlsManager = () => {
const [urls, setUrls] = useState([]);
const [currentUrl, setCurrentUrl] = useState('');
const [editingIndex, setEditingIndex] = useState(null);
const [isEditing, setIsEditing] = useState(false)

const updateJspInputField = (url) => {
document.getElementById('url').value = url;
};

useEffect(() => {
// Add an event listener to the select element
const select = document.getElementById('savedUrls');
if (select) {
select.addEventListener('change', (e) => updateJspInputField(e.target.value));
}

fetch('/UrlManagerGetUrls', {
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
setUrls(data);
updateSelectOptions(data);
})
.catch(error => {
console.error('Error fetching saved URLs:', error);
});

// Remove the event listener when the component unmounts
return () => {
if (select) {
select.removeEventListener('change', (e) => updateJspInputField(e.target.value));
}
};
}, []);


const updateSelectOptions = (urls) => {
const jspUrlInput = document.getElementById('url').value = urls[urls.length - 1]
const select = document.getElementById('savedUrls');
select.innerHTML = '';
urls?.forEach(url => {
const option = document.createElement('option');
option.value = url;
option.text = url;
select.appendChild(option);
});
};


const addUrl = () => {
fetch('/UrlManagerAddUrl', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ url: currentUrl })
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
setUrls(prevUrls => [...prevUrls, currentUrl]);
resetInput();
updateSelectOptions([...urls, currentUrl]);
updateJspInputField(currentUrl); // update the JSP input field
})
.catch(error => {
console.error('Error adding URL:', error);
});
};


const updateUrl = (oldUrl, newUrl) => {
fetch("/UrlManagerUpdateUrl", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ oldUrl, newUrl })
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
setUrls(prevUrls => prevUrls.map(url => url === oldUrl ? newUrl : url));
updateSelectOptions(prevUrls => prevUrls.map(url => url === oldUrl ? newUrl : url));
updateJspInputField(newUrl); // update the JSP input field
})
.catch(error => {
console.error('Error updating URL:', error);
});
};


const deleteUrl = index => {
const urlToDelete = urls[index];
fetch('/UrlManagerDeleteUrl', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ url: urlToDelete })
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
let newUrls = urls.filter((_, i) => i !== index);
setUrls(newUrls);
updateSelectOptions(newUrls);
updateJspInputField(newUrls[0]); // update the JSP input field
})
.catch(error => {
console.error('Error deleting URL:', error);
});
};

const saveUrl = () => {
if (currentUrl) {
const oldUrl = urls[editingIndex];
updateUrl(oldUrl, currentUrl);
resetInput();
}
};

const startEditing = index => {
setCurrentUrl(urls[index]);
setEditingIndex(index);
setIsEditing(true);
};

const resetInput = () => {
setCurrentUrl('');
setEditingIndex(null);
setIsEditing(false);
};

return (
<>
<h2>Saved URLs Manager</h2>
<input
className="form-control form-control-lg"
type="text"
value={currentUrl}
onChange={(e) => setCurrentUrl(e.target.value)}
placeholder="https://"
aria-label="Url"
/>
{isEditing ? (
<button type="button" className="btn btn-primary btn-sm p-1 m-1" onClick={saveUrl}>Save</button>
) : (
<button type="button" className="btn btn-primary btn-sm p-1 m-1" onClick={addUrl}>Add</button>
)}
{urls.map((url, index) => (
<div key={index}>
{url}
<button type="button" className="btn btn-primary btn-sm p-1 m-1" onClick={() => startEditing(index)}>Edit</button>
<button type="button" className="btn btn-secondary btn-sm p-1 m-1" onClick={() => deleteUrl(index)}>Delete</button>
</div>
))}
</>
);
}

export default SavedUrlsManager;
2 changes: 1 addition & 1 deletion tomcat/bin/catalina.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
# signals. Default is "false" unless running on HP-UX in which
# case the default is "true"
# -----------------------------------------------------------------------------

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
darwin=false
Expand Down